[PATCH 00/13] No-debug-info debugging improvements

Pedro Alves
2017-07-13T02:19:36Z

This series stops GDB from assuming that no-debug-info functions
return int, and that no-debug-info variables have type int.

E.g. instead of this, if you have no debug info for glibc:

(gdb) p getenv("PATH")
$1 = -6185

You'll get:

(gdb) p getenv ("PATH")
'getenv' has unknown return type; cast the call to its declared return type
(gdb) p (char *) getenv ("PATH") # now Just Works
$1 = 0x7fffffffe7d7 "/usr/local/bin:/"...
(gdb) p ((char *(*) (const char *)) getenv) ("PATH") # continues working
$1 = 0x7fffffffe7d7 "/usr/local/bin:/"...

And similarly for variables.

While implementing and writing tests for the above, I ran into a few
other problems (as usual...), and fixed them too. Most of the
problems were related to printing static local variables, with the
documented "p klass::method()::static_var" syntax.

One other problem I ran into today while writing the documentation
patch... I wanted to document when to call a no-debug-info function
by casting it to the right function pointer type, and calling that
pointer, and noticed that that doesn't actually work correctly... GDB
always leaves the target function type of the function pointer type as
an unprototyped function, meaning that it applies argument coercion
incorrectly. W00t!

See many more details and rationale on the description of each patch.
Documentation is in the last patch.

Tested on x86-64 GNU/Linux, native and gdbserver, both with and
without glibc debug info. Adds over 3700 new passes:

-# of expected passes 39661
+# of expected passes 43405

I see this series as follow up to the recent "whatis" fixes for Zack's
errno pretty printer:

https://sourceware.org/ml/gdb-patches/2017-06/msg00827.html
https://sourceware.org/ml/gdb-patches/2017-07/msg00018.html

so I put this series on top of those patches in the same branch:

users/palves/whatis

Pedro Alves (13):
Stop assuming no-debug-info functions return int
Introduce OP_VAR_MSYM_VALUE
Make ptype/whatis print function name of functions with no debug info
too
evaluate_subexp_standard: Eliminate one goto
evaluate_subexp_standard: Remove useless assignments
evaluate_subexp_standard: Factor out OP_VAR_VALUE handling.
Stop assuming no-debug-info variables have type int
Eliminate UNOP_MEMVAL_TLS
Handle "p S::method()::static_var" in the C++ parser
Handle "p 'S::method()::static_var'" (quoted) in symbol lookup
Make "p S::method() const::static_var" work too
Fix calling prototyped functions via function pointers
Document "no debug info debugging" improvements

gdb/doc/gdb.texinfo | 90 ++++-
gdb/NEWS | 24 ++
gdb/ada-lang.c | 11 +-
gdb/ada-typeprint.c | 7 +-
gdb/ax-gdb.c | 72 +++-
gdb/c-exp.y | 51 ++-
gdb/c-typeprint.c | 10 +-
gdb/compile/compile-c-symbols.c | 4 +-
gdb/compile/compile-c-types.c | 35 +-
gdb/compile/compile-object-run.c | 3 +-
gdb/cp-namespace.c | 50 +--
gdb/dwarf2read.c | 46 ++-
gdb/elfread.c | 2 +-
gdb/eval.c | 439 ++++++++++++++-------
gdb/expprint.c | 92 +++--
gdb/expression.h | 1 +
gdb/f-typeprint.c | 7 +-
gdb/gcore.c | 2 +-
gdb/gdbtypes.c | 27 +-
gdb/gdbtypes.h | 15 +-
gdb/guile/scm-value.c | 2 +-
gdb/infcall.c | 34 +-
gdb/infcall.h | 19 +-
gdb/linux-fork.c | 6 +-
gdb/linux-tdep.c | 4 +-
gdb/m2-typeprint.c | 11 +-
gdb/minsyms.h | 9 +
gdb/objc-lang.c | 14 +-
gdb/p-typeprint.c | 57 +--
gdb/parse.c | 130 +++---
gdb/parser-defs.h | 2 +
gdb/python/py-value.c | 3 +-
gdb/rust-lang.c | 2 +-
gdb/std-operator.def | 43 +-
gdb/testsuite/gdb.asm/asm-source.exp | 8 +-
.../gdb.base/break-main-file-remove-fail.exp | 2 +-
gdb/testsuite/gdb.base/break-probes.exp | 2 +-
gdb/testsuite/gdb.base/callfuncs.exp | 26 +-
gdb/testsuite/gdb.base/checkpoint.exp | 44 +--
gdb/testsuite/gdb.base/dprintf-detach.exp | 2 +-
gdb/testsuite/gdb.base/infcall-exec.exp | 2 +-
gdb/testsuite/gdb.base/info-os.exp | 8 +-
gdb/testsuite/gdb.base/nodebug.c | 9 +
gdb/testsuite/gdb.base/nodebug.exp | 156 ++++++--
gdb/testsuite/gdb.base/solib-display.exp | 16 +-
gdb/testsuite/gdb.compile/compile-ifunc.exp | 5 +-
gdb/testsuite/gdb.compile/compile.exp | 10 +-
gdb/testsuite/gdb.cp/local-static.c | 170 ++++++++
gdb/testsuite/gdb.cp/local-static.cc | 1 +
gdb/testsuite/gdb.cp/local-static.exp | 241 +++++++++++
gdb/testsuite/gdb.cp/m-static.exp | 5 -
gdb/testsuite/gdb.dwarf2/dw2-skip-prologue.exp | 2 +-
gdb/testsuite/gdb.threads/siginfo-threads.exp | 7 +-
gdb/testsuite/gdb.threads/tls-nodebug.exp | 5 +-
gdb/testsuite/gdb.trace/entry-values.exp | 6 +-
gdb/typeprint.c | 18 +-
gdb/typeprint.h | 9 +
gdb/valarith.c | 4 +-
gdb/valops.c | 7 +-
59 files changed, 1636 insertions(+), 453 deletions(-)
create mode 100644 gdb/testsuite/gdb.cp/local-static.c
create mode 100644 gdb/testsuite/gdb.cp/local-static.cc
create mode 100644 gdb/testsuite/gdb.cp/local-static.exp

--
2.5.5