diff options
author | Pedro Alves <palves@redhat.com> | 2017-09-04 20:21:13 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-09-04 20:21:13 +0100 |
commit | 7022349d5c86bae74b49225515f42d2e221bd368 (patch) | |
tree | dc0ec34d60ef82bf8149d15b985dc36f2a84b167 /gdb/testsuite | |
parent | 54990598c4c74b6af113baf801064d3b1837973f (diff) | |
download | gdb-7022349d5c86bae74b49225515f42d2e221bd368.zip gdb-7022349d5c86bae74b49225515f42d2e221bd368.tar.gz gdb-7022349d5c86bae74b49225515f42d2e221bd368.tar.bz2 |
Stop assuming no-debug-info functions return int
The fact that GDB defaults to assuming that functions return int, when
it has no debug info for the function has been a recurring source of
user confusion. Recently this came up on the errno pretty printer
discussions. Shortly after, it came up again on IRC, with someone
wondering why does getenv() in GDB return a negative int:
(gdb) p getenv("PATH")
$1 = -6185
This question (with s/getenv/random-other-C-runtime-function) is a FAQ
on IRC.
The reason for the above is:
(gdb) p getenv
$2 = {<text variable, no debug info>} 0x7ffff7751d80 <getenv>
(gdb) ptype getenv
type = int ()
... which means that GDB truncated the 64-bit pointer that is actually
returned from getent to 32-bit, and then sign-extended it:
(gdb) p /x -6185
$6 = 0xffffe7d7
The workaround is to cast the function to the right type, like:
(gdb) p ((char *(*) (const char *)) getenv) ("PATH")
$3 = 0x7fffffffe7d7 "/usr/local/bin:/"...
IMO, we should do better than this.
I see the "assume-int" issue the same way I see printing bogus values
for optimized-out variables instead of "<optimized out>" -- I'd much
rather that the debugger tells me "I don't know" and tells me how to
fix it than showing me bogus misleading results, making me go around
tilting at windmills.
If GDB prints a signed integer when you're expecting a pointer or
aggregate, you at least have some sense that something is off, but
consider the case of the function actually returning a 64-bit integer.
For example, compile this without debug info:
unsigned long long
function ()
{
return 0x7fffffffffffffff;
}
Currently, with pristine GDB, you get:
(gdb) p function ()
$1 = -1 # incorrect
(gdb) p /x function ()
$2 = 0xffffffff # incorrect
maybe after spending a few hours debugging you suspect something is
wrong with that -1, and do:
(gdb) ptype function
type = int ()
and maybe, just maybe, you realize that the function actually returns
unsigned long long. And you try to fix it with:
(gdb) p /x (unsigned long long) function ()
$3 = 0xffffffffffffffff # incorrect
... which still produces the wrong result, because GDB simply applied
int to unsigned long long conversion. Meaning, it sign-extended the
integer that it extracted from the return of the function, to 64-bits.
and then maybe, after asking around on IRC, you realize you have to
cast the function to a pointer of the right type, and call that. It
won't be easy, but after a few missteps, you'll get to it:
..... (gdb) p /x ((unsigned long long(*) ()) function) ()
$666 = 0x7fffffffffffffff # finally! :-)
So to improve on the user experience, this patch does the following
(interrelated) things:
- makes no-debug-info functions no longer default to "int" as return
type. Instead, they're left with NULL/"<unknown return type>"
return type.
(gdb) ptype getenv
type = <unknown return type> ()
- makes calling a function with unknown return type an error.
(gdb) p getenv ("PATH")
'getenv' has unknown return type; cast the call to its declared return type
- and then to make it easier to call the function, makes it possible
to _only_ cast the return of the function to the right type,
instead of having to cast the function to a function pointer:
(gdb) p (char *) getenv ("PATH") # now Just Works
$3 = 0x7fffffffe7d7 "/usr/local/bin:/"...
(gdb) p ((char *(*) (const char *)) getenv) ("PATH") # continues working
$4 = 0x7fffffffe7d7 "/usr/local/bin:/"...
I.e., it makes GDB default the function's return type to the type
of the cast, and the function's parameters to the type of the
arguments passed down.
After this patch, here's what you'll get for the "unsigned long long"
example above:
(gdb) p function ()
'function' has unknown return type; cast the call to its declared return type
(gdb) p /x (unsigned long long) function ()
$4 = 0x7fffffffffffffff # correct!
Note that while with "print" GDB shows the name of the function that
has the problem:
(gdb) p getenv ("PATH")
'getenv' has unknown return type; cast the call to its declared return type
which can by handy in more complicated expressions, "ptype" does not:
(gdb) ptype getenv ("PATH")
function has unknown return type; cast the call to its declared return type
This will be fixed in the next patch.
gdb/ChangeLog:
2017-09-04 Pedro Alves <palves@redhat.com>
* ada-lang.c (ada_evaluate_subexp) <TYPE_CODE_FUNC>: Don't handle
TYPE_GNU_IFUNC specially here. Throw error if return type is
unknown.
* ada-typeprint.c (print_func_type): Handle functions with unknown
return type.
* c-typeprint.c (c_type_print_base): Handle functions and methods
with unknown return type.
* compile/compile-c-symbols.c (convert_symbol_bmsym)
<mst_text_gnu_ifunc>: Use nodebug_text_gnu_ifunc_symbol.
* compile/compile-c-types.c: Include "objfiles.h".
(convert_func): For functions with unknown return type, warn and
default to int.
* compile/compile-object-run.c (compile_object_run): Adjust call
to call_function_by_hand_dummy.
* elfread.c (elf_gnu_ifunc_resolve_addr): Adjust call to
call_function_by_hand.
* eval.c (evaluate_subexp_standard): Adjust calls to
call_function_by_hand. Handle functions and methods with unknown
return type. Pass expect_type to call_function_by_hand.
* f-typeprint.c (f_type_print_base): Handle functions with unknown
return type.
* gcore.c (call_target_sbrk): Adjust call to
call_function_by_hand.
* gdbtypes.c (objfile_type): Leave nodebug text symbol with NULL
return type instead of int. Make nodebug_text_gnu_ifunc_symbol be
an integer address type instead of nodebug.
* guile/scm-value.c (gdbscm_value_call): Adjust call to
call_function_by_hand.
* infcall.c (error_call_unknown_return_type): New function.
(call_function_by_hand): New "default_return_type" parameter.
Pass it down.
(call_function_by_hand_dummy): New "default_return_type"
parameter. Use it instead of defaulting to int. If there's no
default and the return type is unknown, throw an error. If
there's a default return type, and the called function has no
debug info, then assume the function is prototyped.
* infcall.h (call_function_by_hand, call_function_by_hand_dummy):
New "default_return_type" parameter.
(error_call_unknown_return_type): New declaration.
* linux-fork.c (call_lseek): Cast return type of lseek.
(inferior_call_waitpid, checkpoint_command): Adjust calls to
call_function_by_hand.
* linux-tdep.c (linux_infcall_mmap, linux_infcall_munmap): Adjust
calls to call_function_by_hand.
* m2-typeprint.c (m2_procedure): Handle functions with unknown
return type.
* objc-lang.c (lookup_objc_class, lookup_child_selector)
(value_nsstring, print_object_command): Adjust calls to
call_function_by_hand.
* p-typeprint.c (pascal_type_print_varspec_prefix): Handle
functions with unknown return type.
(pascal_type_print_func_varspec_suffix): New function.
(pascal_type_print_varspec_suffix) <TYPE_CODE_FUNC,
TYPE_CODE_METHOD>: Use it.
* python/py-value.c (valpy_call): Adjust call to
call_function_by_hand.
* rust-lang.c (rust_evaluate_funcall): Adjust call to
call_function_by_hand.
* valarith.c (value_x_binop, value_x_unop): Adjust calls to
call_function_by_hand.
* valops.c (value_allocate_space_in_inferior): Adjust call to
call_function_by_hand.
* typeprint.c (type_print_unknown_return_type): New function.
* typeprint.h (type_print_unknown_return_type): New declaration.
gdb/testsuite/ChangeLog:
2017-09-04 Pedro Alves <palves@redhat.com>
* gdb.base/break-main-file-remove-fail.exp (test_remove_bp): Cast
return type of munmap in infcall.
* gdb.base/break-probes.exp: Cast return type of foo in infcall.
* gdb.base/checkpoint.exp: Simplify using for loop. Cast return
type of ftell in infcall.
* gdb.base/dprintf-detach.exp (dprintf_detach_test): Cast return
type of getpid in infcall.
* gdb.base/infcall-exec.exp: Cast return type of execlp in
infcall.
* gdb.base/info-os.exp: Cast return type of getpid in infcall.
Bail on failure to extract the pid.
* gdb.base/nodebug.c: #include <stdint.h>.
(multf, multf_noproto, mult, mult_noproto, add8, add8_noproto):
New functions.
* gdb.base/nodebug.exp (test_call_promotion): New procedure.
Change expected output of print/whatis/ptype with functions with
no debug info. Test all supported languages. Call
test_call_promotion.
* gdb.compile/compile.exp: Adjust expected output to expect
warning.
* gdb.threads/siginfo-threads.exp: Likewise.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 24 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/break-main-file-remove-fail.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/break-probes.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/checkpoint.exp | 44 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/dprintf-detach.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/infcall-exec.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/info-os.exp | 8 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/nodebug.c | 41 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/nodebug.exp | 122 | ||||
-rw-r--r-- | gdb/testsuite/gdb.compile/compile.exp | 10 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/siginfo-threads.exp | 7 |
11 files changed, 199 insertions, 65 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 35c5928..c00c300 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,29 @@ 2017-09-04 Pedro Alves <palves@redhat.com> + * gdb.base/break-main-file-remove-fail.exp (test_remove_bp): Cast + return type of munmap in infcall. + * gdb.base/break-probes.exp: Cast return type of foo in infcall. + * gdb.base/checkpoint.exp: Simplify using for loop. Cast return + type of ftell in infcall. + * gdb.base/dprintf-detach.exp (dprintf_detach_test): Cast return + type of getpid in infcall. + * gdb.base/infcall-exec.exp: Cast return type of execlp in + infcall. + * gdb.base/info-os.exp: Cast return type of getpid in infcall. + Bail on failure to extract the pid. + * gdb.base/nodebug.c: #include <stdint.h>. + (multf, multf_noproto, mult, mult_noproto, add8, add8_noproto): + New functions. + * gdb.base/nodebug.exp (test_call_promotion): New procedure. + Change expected output of print/whatis/ptype with functions with + no debug info. Test all supported languages. Call + test_call_promotion. + * gdb.compile/compile.exp: Adjust expected output to expect + warning. + * gdb.threads/siginfo-threads.exp: Likewise. + +2017-09-04 Pedro Alves <palves@redhat.com> + * gdb.base/callfuncs.exp (do_function_calls): New parameter "prototypes". Test calling float functions via prototyped and unprototyped function pointers. diff --git a/gdb/testsuite/gdb.base/break-main-file-remove-fail.exp b/gdb/testsuite/gdb.base/break-main-file-remove-fail.exp index eba72bc..080d193 100644 --- a/gdb/testsuite/gdb.base/break-main-file-remove-fail.exp +++ b/gdb/testsuite/gdb.base/break-main-file-remove-fail.exp @@ -88,7 +88,7 @@ proc test_remove_bp { initial_load } { # should warn the user about it. set pagesize [get_integer_valueof "pg_size" 0] set align_addr [expr $bp_addr - $bp_addr % $pagesize] - set munmap [get_integer_valueof "munmap ($align_addr, $pagesize)" -1] + set munmap [get_integer_valueof "(int) munmap ($align_addr, $pagesize)" -1] if {$munmap != 0} { unsupported "can't munmap foo's page" diff --git a/gdb/testsuite/gdb.base/break-probes.exp b/gdb/testsuite/gdb.base/break-probes.exp index 929509a..318a219 100644 --- a/gdb/testsuite/gdb.base/break-probes.exp +++ b/gdb/testsuite/gdb.base/break-probes.exp @@ -86,5 +86,5 @@ if { $using_probes } { } # Call something to ensure that relocation occurred - gdb_test "call foo(23)" "\\\$.* = 31.*\\\M.*" + gdb_test "call (int) foo(23)" "\\\$.* = 31.*\\\M.*" } diff --git a/gdb/testsuite/gdb.base/checkpoint.exp b/gdb/testsuite/gdb.base/checkpoint.exp index 12c1d8a..677c389 100644 --- a/gdb/testsuite/gdb.base/checkpoint.exp +++ b/gdb/testsuite/gdb.base/checkpoint.exp @@ -224,45 +224,11 @@ gdb_test "shell diff $pi_txt $copy1_txt" \ delete_breakpoints gdb_breakpoint $break2_loc -gdb_test "restart 1" "if .c == EOF.*" "restart 1 three" -gdb_test "continue" "breakpoint 2.*" "break2 1 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 1" - -gdb_test "restart 2" "if .c == EOF.*" "restart 2 three" -gdb_test "continue" "breakpoint 2.*" "break2 2 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 2" - -gdb_test "restart 3" "if .c == EOF.*" "restart 3 three" -gdb_test "continue" "breakpoint 2.*" "break2 3 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 3" - -gdb_test "restart 4" "if .c == EOF.*" "restart 4 three" -gdb_test "continue" "breakpoint 2.*" "break2 4 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 4" - -gdb_test "restart 5" "if .c == EOF.*" "restart 5 three" -gdb_test "continue" "breakpoint 2.*" "break2 5 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 5" - -gdb_test "restart 6" "if .c == EOF.*" "restart 6 three" -gdb_test "continue" "breakpoint 2.*" "break2 6 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 6" - -gdb_test "restart 7" "if .c == EOF.*" "restart 7 three" -gdb_test "continue" "breakpoint 2.*" "break2 7 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 7" - -gdb_test "restart 8" "if .c == EOF.*" "restart 8 three" -gdb_test "continue" "breakpoint 2.*" "break2 8 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 8" - -gdb_test "restart 9" "if .c == EOF.*" "restart 9 three" -gdb_test "continue" "breakpoint 2.*" "break2 9 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 9" - -gdb_test "restart 10" "if .c == EOF.*" "restart 10 three" -gdb_test "continue" "breakpoint 2.*" "break2 10 one" -gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 10" +for {set num 1} {$num <= 10} {incr num} { + gdb_test "restart $num" "if .c == EOF.*" "restart $num three" + gdb_test "continue" "breakpoint 2.*" "break2 $num one" + gdb_test "print (long) ftell (out) > 100000" " = 1.*" "outfile still open $num" +} # # Now confirm that if one fork exits, we automatically switch to another one. diff --git a/gdb/testsuite/gdb.base/dprintf-detach.exp b/gdb/testsuite/gdb.base/dprintf-detach.exp index 4c6ef1c..940a9ef 100644 --- a/gdb/testsuite/gdb.base/dprintf-detach.exp +++ b/gdb/testsuite/gdb.base/dprintf-detach.exp @@ -53,7 +53,7 @@ proc dprintf_detach_test { breakpoint_always_inserted dprintf_style disconnected # Get PID of test program. set inferior_pid -1 set test "get inferior process ID" - gdb_test_multiple "call getpid ()" $test { + gdb_test_multiple "call (int) getpid ()" $test { -re ".* = ($decimal).*$gdb_prompt $" { set inferior_pid $expect_out(1,string) pass $test diff --git a/gdb/testsuite/gdb.base/infcall-exec.exp b/gdb/testsuite/gdb.base/infcall-exec.exp index 3984076..8419905 100644 --- a/gdb/testsuite/gdb.base/infcall-exec.exp +++ b/gdb/testsuite/gdb.base/infcall-exec.exp @@ -44,5 +44,5 @@ append expected_result "\[\r\n\]+.*" append expected_result "Breakpoint 1, main .*at .*$srcfile2:$decimal" append expected_result ".*" -gdb_test "call execlp \(\"$binfile2\", \"$binfile2\", \(char \*\)0\)" \ +gdb_test "call (int) execlp \(\"$binfile2\", \"$binfile2\", \(char \*\)0\)" \ $expected_result "call execlp" diff --git a/gdb/testsuite/gdb.base/info-os.exp b/gdb/testsuite/gdb.base/info-os.exp index 0168ccb..574da26 100644 --- a/gdb/testsuite/gdb.base/info-os.exp +++ b/gdb/testsuite/gdb.base/info-os.exp @@ -39,14 +39,18 @@ if ![runto_main] then { } # Get PID of test program. -set inferior_pid -1 +set inferior_pid "" set test "get inferior process ID" -gdb_test_multiple "call getpid()" $test { +gdb_test_multiple "call (int) getpid()" $test { -re ".* = ($decimal).*$gdb_prompt $" { set inferior_pid $expect_out(1,string) pass $test } } +if {$inferior_pid == ""} { + untested "failed to get pid" + return +} gdb_breakpoint ${srcfile}:[gdb_get_line_number "Set breakpoint here"] gdb_continue_to_breakpoint "Set breakpoint here" diff --git a/gdb/testsuite/gdb.base/nodebug.c b/gdb/testsuite/gdb.base/nodebug.c index eb5d661..99641e8 100644 --- a/gdb/testsuite/gdb.base/nodebug.c +++ b/gdb/testsuite/gdb.base/nodebug.c @@ -1,4 +1,6 @@ #include <stdlib.h> +#include <stdint.h> + /* Test that things still (sort of) work when compiled without -g. */ int dataglobal = 3; /* Should go in global data */ @@ -43,3 +45,42 @@ int array_index (char *arr, int i) free (x); return retval; } + +float +multf (float v1, float v2) +{ + return v1 * v2; +} + +float +multf_noproto (v1, v2) + float v1, v2; +{ + return v1 * v2; +} + +double +mult (double v1, double v2) +{ + return v1 * v2; +} + +double +mult_noproto (v1, v2) + double v1, v2; +{ + return v1 * v2; +} + +uint8_t +add8 (uint8_t v1, uint8_t v2) +{ + return v1 + v2; +} + +uint8_t +add8_noproto (v1, v2) + uint8_t v1, v2; +{ + return v1 + v2; +} diff --git a/gdb/testsuite/gdb.base/nodebug.exp b/gdb/testsuite/gdb.base/nodebug.exp index a54e5bb..7bdf9ad 100644 --- a/gdb/testsuite/gdb.base/nodebug.exp +++ b/gdb/testsuite/gdb.base/nodebug.exp @@ -39,6 +39,40 @@ if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != " clean_restart $binfile +# Test calling no-debug functions involving argument types that may +# require coercion/promotion, both prototyped and unprototyped, both +# return-type-cast style, and function-pointer-cast styles. +proc test_call_promotion {} { + if [target_info exists gdb,cannot_call_functions] { + return + } + + # Call prototyped function with float parameters via both + # return-type cast and function-pointer cast. This checks that + # GDB doesn't do float->double coercion. + gdb_test "p (float) multf(2.0f, 3.0f)" " = 6" + gdb_test "p ((float (*) (float, float)) multf)(2, 3)" " = 6" + gdb_test "p ((float (*) (float, float)) multf)(2.0f, 3.0f)" " = 6" + + # Call unprototyped function with float parameters via + # function-pointer cast, only. return-type cast assumes + # protototyped. Check that GDB does float->double coercion. + gdb_test "p ((float (*) ()) multf_noproto)(2.0f, 3.0f)" " = 6" + gdb_test "p ((float (*) ()) multf_noproto)(2.0, 3.0)" " = 6" + + # Same, but for double. + gdb_test "p (double) mult (2.0, 3.0)" " = 6" + gdb_test "p ((double (*) (double, double)) mult)(2.0f, 3.0f)" " = 6" + gdb_test "p ((double (*) (double, double)) mult)(2, 3)" " = 6" + gdb_test "p ((double (*) ()) mult_noproto)(2.0f, 3.0f)" " = 6" + gdb_test "p ((double (*) ()) mult_noproto)(2.0, 3.0)" " = 6" + + # Check that GDB promotes char->int correctly. + gdb_test "p /d (uint8) add8((uint8) 2, (uint8) 3)" " = 5" + gdb_test "p /d ((uint8 (*) (uint8, uint8)) add8)((uint8) 2, (uint8) 3)" " = 5" + gdb_test "p /d ((uint8 (*) ()) add8_noproto)((uint8) 2, (uint8) 3)" " = 5" +} + if [runto inner] then { # Expect to find global/local symbols in each of text/data/bss. @@ -59,18 +93,66 @@ if [runto inner] then { # out debugging info for non-aggregate return values of functions # even without -g, which should be accepted. - gdb_test "p top" \ - "\{(<(text variable|function), no debug info>|short \\(int\\)|short \\(\\))\} \[0-9a-fx]* <\\.?top(\\(int\\)|)>" - gdb_test "whatis top" \ - "(<(text variable|function), no debug info>|short \\(int\\)|short \\(\\))" - gdb_test "ptype top" "(short|int) \\((|void|int|<non-float parameter>|<non-float parameter>, <non-float parameter>)\\)" - - gdb_test "p middle" \ - "\{(<(text variable|function), no debug info>|short \\(int\\)|short \\(\\))\} \[0-9a-fx]* <\\.?middle(\\(int\\)|)>" - gdb_test "whatis middle" \ - "(<(text variable|function), no debug info>|short \\(int\\)|short \\(\\))" - gdb_test "ptype middle" "(short|int) \\((|void|int|<non-float parameter>|<non-float parameter>, <non-float parameter>)\\)" - + with_test_prefix "func" { + # Most languages default to printing like C. + set c_print_re " = \\{<text variable, no debug info>\\} $hex <top>" + set c_whatis_re " = <text variable, no debug info>" + set c_ptype_re "= <unknown return type> \\(\\)" + + set cxx_ptype_re "= <unknown return type> \\(void\\)" + + set ada_ptype_re " = function return <unknown return type>" + + set m2_print_re " = \\{PROCEDURE <text variable, no debug info> \\(\\) : <unknown return type>\\} $hex <top>" + set m2_whatis_re "PROCEDURE <text variable, no debug info> \\(\\) : <unknown return type>" + set m2_ptype_re $m2_whatis_re + + # Rust can't access minsyms? + set rust_nosym "No symbol 'top' in current context" + + set pascal_ptype_re "type = procedure : <unknown return type>" + + #LANG #PRINT #WHATIS #PTYPE + foreach lang_line { + {"ada" $c_print_re $c_whatis_re $ada_ptype_re} + {"asm" $c_print_re $c_whatis_re $c_ptype_re} + {"c" $c_print_re $c_whatis_re $c_ptype_re} + {"c++" $c_print_re $c_whatis_re $cxx_ptype_re} + {"d" $c_print_re $c_whatis_re $c_ptype_re} + {"fortran" $c_print_re $c_whatis_re $c_ptype_re} + {"go" $c_print_re $c_whatis_re $c_ptype_re} + {"minimal" $c_print_re $c_whatis_re $c_ptype_re} + {"modula-2" $m2_print_re $m2_whatis_re $m2_ptype_re} + {"objective-c" $c_print_re $c_whatis_re $c_ptype_re} + {"opencl" $c_print_re $c_whatis_re $c_ptype_re} + {"pascal" $c_print_re $c_whatis_re $pascal_ptype_re} + {"rust" $rust_nosym $rust_nosym $rust_nosym} + } { + set lang [lindex $lang_line 0] + set print_re [lindex $lang_line 1] + set whatis_re [lindex $lang_line 2] + set ptype_re [lindex $lang_line 3] + + set print_re [subst "$print_re"] + set whatis_re [subst "$whatis_re"] + set ptype_re [subst "$ptype_re"] + + with_test_prefix "$lang" { + gdb_test_no_output "set language $lang" + gdb_test "p top" $print_re + gdb_test "whatis top" $whatis_re + gdb_test "ptype top" $ptype_re + } + } + } + + gdb_test_no_output "set language auto" + + # We can't rely on uintXX_t being available/known to GDB because + # we may or may not have debug info for those (depending on + # whether we have debug info for the C runtime, for example). + gdb_test_no_output "macro define uint8 unsigned char" + gdb_test "p dataglobal" "= 3" gdb_test "whatis dataglobal" \ "<(data variable|variable), no debug info>|int" @@ -122,17 +204,27 @@ if [runto inner] then { # This test is not as obscure as it might look. `p getenv ("TERM")' # is a real-world example, at least on many systems. + + gdb_test {p/c array_index("abcdef",2)} \ + "'array_index' has unknown return type; cast the call to its declared return type" + gdb_test {ptype array_index("abcdef",2)} \ + "function has unknown return type; cast the call to its declared return type" + gdb_test {whatis array_index("abcdef",2)} \ + "function has unknown return type; cast the call to its declared return type" + if [target_info exists gdb,cannot_call_functions] { - unsupported "p/c array_index(\"abcdef\",2)" + unsupported "p/c (int) array_index(\"abcdef\",2)" } else { # We need to up this because this can be really slow on some boards. # (malloc() is called as part of the test). set prev_timeout $timeout set timeout 60 - gdb_test {p/c array_index("abcdef",2)} " = 99 'c'" + gdb_test {p/c (int) array_index("abcdef",2)} " = 99 'c'" set timeout $prev_timeout } - + + test_call_promotion + # Now, try that we can give names of file-local symbols which happen # to be unique, and have it still work if [runto middle] then { diff --git a/gdb/testsuite/gdb.compile/compile.exp b/gdb/testsuite/gdb.compile/compile.exp index b221870..c23ff6a 100644 --- a/gdb/testsuite/gdb.compile/compile.exp +++ b/gdb/testsuite/gdb.compile/compile.exp @@ -296,12 +296,14 @@ gdb_test "p globalvar" " = 77" "expect 77" # Test reference to minimal_symbol, not (full) symbol. -gdb_test_no_output "compile code globalvar = func_nodebug (75);" \ +gdb_test "compile code globalvar = func_nodebug (75);" \ + "warning: function has unknown return type; assuming int" \ "call func_nodebug" gdb_test "p globalvar" " = -75" "expect -75" -gdb_test_no_output \ - "compile code int (*funcp) (int) = func_nodebug; globalvar = funcp (76);" \ - "call func_nodebug indirectly" +gdb_test \ + "compile code int (*funcp) (int) = func_nodebug; globalvar = funcp (76);" \ + "warning: function has unknown return type; assuming int" \ + "call func_nodebug indirectly" gdb_test "p globalvar" " = -76" "expect -76" diff --git a/gdb/testsuite/gdb.threads/siginfo-threads.exp b/gdb/testsuite/gdb.threads/siginfo-threads.exp index 328168c..8ee4c36 100644 --- a/gdb/testsuite/gdb.threads/siginfo-threads.exp +++ b/gdb/testsuite/gdb.threads/siginfo-threads.exp @@ -40,12 +40,17 @@ gdb_test "handle SIGUSR2 stop print pass" \ gdb_breakpoint [gdb_get_line_number "break-at-exit"] set test "get pid" -gdb_test_multiple "p getpid ()" $test { +set pid "" +gdb_test_multiple "p (int) getpid ()" $test { -re " = (\[0-9\]+)\r\n$gdb_prompt $" { set pid $expect_out(1,string) pass $test } } +if {$pid == ""} { + untested "failed to get pid" + return +} for {set sigcount 0} {$sigcount < 4} {incr sigcount} { set test "catch signal $sigcount" |