c2go icon indicating copy to clipboard operation
c2go copied to clipboard

panic: could not match regexp with string

Open s4kibs4mi opened this issue 5 years ago • 4 comments

Error :

panic: could not match regexp with string
^(?P<address>[0-9a-fx]+) <(?P<position>.*)> '(?P<type>.*?)'(:'(?P<type2>.*?)')? <(?P<kind>.*)>[\s]*$
0x7fe6fc85a348 <col:56> 'int' <LValueToRValue> part_of_explicit_cast


goroutine 12 [running]:
github.com/elliotchance/c2go/ast.groupsFromRegex(0xc000210af0, 0x64, 0xc0002b3409, 0x44, 0xc00037bde0)
	/Users/sakib/go/src/github.com/elliotchance/c2go/ast/ast.go:286 +0x360
github.com/elliotchance/c2go/ast.parseImplicitCastExpr(0xc0002b3409, 0x44, 0x12c0246)
	/Users/sakib/go/src/github.com/elliotchance/c2go/ast/implicit_cast_expr.go:17 +0x62
github.com/elliotchance/c2go/ast.Parse(0xc0002b33f8, 0x55, 0x12baa29, 0x5)
	/Users/sakib/go/src/github.com/elliotchance/c2go/ast/ast.go:154 +0x306a
main.convertLinesToNodes(0xc0002bbae0, 0xd7, 0x1af, 0x0, 0x0, 0x0)
	/Users/sakib/go/src/github.com/elliotchance/c2go/main.go:89 +0x1a6
main.convertLinesToNodesParallel.func1.1(0xc000228540, 0xc00000e088, 0xc0002bbae0, 0xd7, 0x1af, 0x0)
	/Users/sakib/go/src/github.com/elliotchance/c2go/main.go:113 +0x53
created by main.convertLinesToNodesParallel.func1
	/Users/sakib/go/src/github.com/elliotchance/c2go/main.go:111 +0x124

Source :

#include <stdio.h>

void genFib(int x, int y, int n) {
	if (n == 0){
		return;
	}

	printf("%d\n", x);
	return genFib(y, x + y, --n);
}

int main() {
	genFib(1, 1, 10);
	return 0;
}

s4kibs4mi avatar Sep 11 '19 06:09 s4kibs4mi

This is becuase c2go doesn't recognise one of the AST lines generated from clang. The regexp will need to be updated so it can be understood.

If you want to have a go at fixing this, you can find an example here: https://github.com/elliotchance/c2go/pull/760

elliotchance avatar Sep 12 '19 02:09 elliotchance

@s4kibs4mi :Did you find solution for your problem?

I am also getting similar error. Please suggest how to proceed for this.

AvinashRamashray avatar Nov 05 '19 19:11 AvinashRamashray

@elliotchance, I too have just experienced this issue.

Maybe the regex is too strict and needs to more forgiving for other formats. Perhaps the idea, if the information I need is there, use it, and if there is more, ignore it.

Instead of updating the regex for my specific line:

panic: could not match regexp with string
^(?P<address>[0-9a-fx]+) <(?P<position>.*)>(?P<inherited> Inherited)? (?P<os>\w+) (?P<version>[\d.]+) (?P<unknown1>[\d.]+) (?P<unknown2>[\d.]+)(?P<unavalable> Unavailable)? "(?P<message1>.*?)"(?P<message2> ".*?")?[\s]*$
0x7fddc201bf28 <col:99, col:134> macos 10.13 0 0 "" "" 0

Maybe we can clean this up.

The issue #760 seems to build a regex from another regex. Can you point me in the direction where the tests for these are?

jtarchie avatar May 01 '20 18:05 jtarchie

@jtarchie because c2go parses the string rendered AST tree produced from clang there's a lot of edge cases, especially as clang gains more features, as the AWS output is just for debugging, it's not intended to be a porcelain format.

I originally wanted to keep the regex as tight as possible to make sure the structs that represent the data don't become dirty over or out of sync over time, because it's such an easy to update a case when it's found. You can find all the test cases and node types in the ast package: https://github.com/elliotchance/c2go/tree/master/ast

If it's an existing node type you can add a new test case for it, here is an example of adding a fix: https://github.com/elliotchance/c2go/pull/853

elliotchance avatar May 04 '20 14:05 elliotchance