aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-09-04 20:21:14 +0100
committerPedro Alves <palves@redhat.com>2017-09-04 20:21:14 +0100
commit2c5a2be1902b50e34411baa57ff0b747e8e20e8b (patch)
tree664d7cd890e1ea1bcdbf8449d9350377291fb307 /gdb
parent74ea4be48e1247b8f7c50fd3578c468f2ff1ae25 (diff)
downloadgdb-2c5a2be1902b50e34411baa57ff0b747e8e20e8b.zip
gdb-2c5a2be1902b50e34411baa57ff0b747e8e20e8b.tar.gz
gdb-2c5a2be1902b50e34411baa57ff0b747e8e20e8b.tar.bz2
Make ptype/whatis print function name of functions with no debug info too
The patch to make GDB stop assuming functions return int left GDB with an inconsistency. While with normal expression evaluation the "unknown return type" error shows the name of the function that misses debug info: (gdb) p getenv ("PATH") 'getenv' has unknown return type; cast the call to its declared return type ^^^^^^ which is 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 commit builds on the new OP_VAR_MSYM_VALUE to fix it, by making OP_FUNCALL extract the function name from the symbol stored in OP_VAR_VALUE/OP_VAR_MSYM_VALUE. We now get the same error in "print" vs "ptype": (gdb) ptype getenv() 'getenv' has unknown return type; cast the call to its declared return type (gdb) p getenv() 'getenv' has unknown return type; cast the call to its declared return type gdb/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * eval.c (evaluate_subexp_standard): <OP_FUNCALL>: Extract function name from symbol/minsym and pass it to error_call_unknown_return_type. gdb/testsuite/ChangeLog: 2017-09-04 Pedro Alves <palves@redhat.com> * gdb.base/nodebug.exp: Test that ptype's error about functions with unknown return type includes the function name too.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/eval.c14
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/nodebug.exp12
4 files changed, 28 insertions, 9 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d34b29a..105c1db 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2017-09-04 Pedro Alves <palves@redhat.com>
+ * eval.c (evaluate_subexp_standard): <OP_FUNCALL>: Extract
+ function name from symbol/minsym and pass it to
+ error_call_unknown_return_type.
+
+2017-09-04 Pedro Alves <palves@redhat.com>
+
* ada-lang.c (resolve_subexp): Handle OP_VAR_MSYM_VALUE.
* ax-gdb.c (gen_msym_var_ref): New function.
(gen_expr): Handle OP_VAR_MSYM_VALUE.
diff --git a/gdb/eval.c b/gdb/eval.c
index 457e280..0e77f0a 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -716,6 +716,7 @@ evaluate_subexp_standard (struct type *expect_type,
int save_pos1;
struct symbol *function = NULL;
char *function_name = NULL;
+ const char *var_func_name = NULL;
pc = (*pos)++;
op = exp->elts[pc].opcode;
@@ -1545,6 +1546,17 @@ evaluate_subexp_standard (struct type *expect_type,
}
else
{
+ if (op == OP_VAR_MSYM_VALUE)
+ {
+ symbol *sym = exp->elts[*pos + 2].symbol;
+ var_func_name = SYMBOL_PRINT_NAME (sym);
+ }
+ else if (op == OP_VAR_VALUE)
+ {
+ minimal_symbol *msym = exp->elts[*pos + 2].msymbol;
+ var_func_name = MSYMBOL_PRINT_NAME (msym);
+ }
+
argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
type = value_type (argvec[0]);
if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
@@ -1761,7 +1773,7 @@ evaluate_subexp_standard (struct type *expect_type,
return_type = expect_type;
if (return_type == NULL)
- error_call_unknown_return_type (NULL);
+ error_call_unknown_return_type (var_func_name);
return allocate_value (return_type);
}
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c00c300..5457aa1 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2017-09-04 Pedro Alves <palves@redhat.com>
+ * gdb.base/nodebug.exp: Test that ptype's error about functions
+ with unknown return type includes the function name too.
+
+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.
diff --git a/gdb/testsuite/gdb.base/nodebug.exp b/gdb/testsuite/gdb.base/nodebug.exp
index 7bdf9ad..da704f1 100644
--- a/gdb/testsuite/gdb.base/nodebug.exp
+++ b/gdb/testsuite/gdb.base/nodebug.exp
@@ -204,14 +204,10 @@ 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"
-
+ foreach cmd {"p/c" "ptype" "whatis"} {
+ gdb_test "$cmd array_index(\"abcdef\",2)" \
+ "'array_index' has unknown return type; cast the call to its declared return type"
+ }
if [target_info exists gdb,cannot_call_functions] {
unsupported "p/c (int) array_index(\"abcdef\",2)"
} else {