This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Diagnose invalid pointer arithmetic on gdb.Value
On 09/21/2016 12:07 PM, Jonathan Wakely wrote:
> Here's a patch to do that. None of the existing tests needed to change
> as far as I can see. gdb.base/pointers.exp and gdb.base/completion.exp
> have tests that try to match the old error, but they're commented out.
>
> I kept my additions to py-value.exp that do invalid pointer
> arithmetic, updating the expected text. Should I move that to
> gdb.base/pointers.exp instead? Or check it in both?
>
If we keep only one set, then I think moving is appropriate.
Though I guess having both would be nice, as potentially Python
layer changes can mess this up too. Belt and suspenders.
If you could do that, it'd be great.
+ gdb_test_multiple "python print ('result = ' + str(a+0.5))" "catch error in python type conversion" {
+ -re "Invalid arguments to pointer arithmetic operation..*$gdb_prompt $" {pass "catch error in python type conversion"}
+ -re "result = .*$gdb_prompt $" {fail "catch error in python type conversion"}
+ -re "$gdb_prompt $" {fail "catch error in python type conversion"}
+ }
+
+ gdb_test_multiple "python print ('result = ' + str(0.5+a))" "catch error in python type conversion" {
+ -re "Invalid arguments to pointer arithmetic operation..*$gdb_prompt $" {pass "catch error in python type conversion"}
+ -re "result = .*$gdb_prompt $" {fail "catch error in python type conversion"}
+ -re "$gdb_prompt $" {fail "catch error in python type conversion"}
+ }
+
+ gdb_test_multiple "python print ('result = ' + str(a-0.5))" "catch error in python type conversion" {
+ -re "Invalid arguments to pointer arithmetic operation..*$gdb_prompt $" {pass "catch error in python type conversion"}
+ -re "result = .*$gdb_prompt $" {fail "catch error in python type conversion"}
+ -re "$gdb_prompt $" {fail "catch error in python type conversion"}
+ }
}
BTW, I noticed that this using the same test message in all cases,
which is a problem we've been slowing fixing:
https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Make_sure_test_messages_are_unique
I see that the test is already violating that, but I'd prefer to
not make it worse. (see below).
Also, while at it, and I know its a preexisting pattern in the
test that you're copying, but there's really no reason to have the
three regexs per test. The latter two in all cases are unnecessary,
as gdb_test_multiple has a fallback fail case for "$gdb_prompt $".
So if the first -re line doesn't match we'd get a fail anyway.
What this means is that the tests could be simplified to use gdb_test
instead. Say, like:
gdb_test "python print ('result = ' + str(a+0.5))" \
"Invalid arguments to pointer arithmetic operation..*" \
"catch error in python type conversion: a+0.5"
gdb_test "python print ('result = ' + str(0.5+a))" \
"Invalid arguments to pointer arithmetic operation..*" \
"catch error in python type conversion: 0.5+a"
gdb_test "python print ('result = ' + str(a-0.5))" \
"Invalid arguments to pointer arithmetic operation..*" \
"catch error in python type conversion: a-0.5"
Thanks,
Pedro Alves