This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
unbreak "maint print registers" with no program running
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 20 Apr 2011 18:12:35 +0100
- Subject: unbreak "maint print registers" with no program running
"maint print registers" and relatives got broken a while back,
when used without being connected to a running target:
(gdb) maint print registers
../../src/gdb/inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
This command is useful without a running program to
debug register cache layout issues.
We get to get_thread_arch_regcache with a null_ptid,
and then ask the target for that ptid's address space, which
is not valid.
The fix is just to add a special case for null_ptid to
get_thread_arch_regcache.
ptid_is_pid is used later when getting rid of the
new regcache for null_ptid, and we'd now hit the assertion
I'm removing. I had put this assertion there to catch
easy mistakes, but it's now tripping a real use.
Applied on mainline and 7.3.
Pedro Alves
2011-04-20 Pedro Alves <pedro@codesourcery.com>
gdb/
* regcache.c (get_thread_arch_regcache): If creating a regcache for
null_ptid, assume and allow a NULL address space, instead of
asking the target for the ptid's address space.
* infrun.c (ptid_is_pid): Remove assertion.
gdb/testsuite/
* gdb.base/maint.exp: Test that "maint print registers" works
without a running program.
---
gdb/infrun.c | 5 -----
gdb/regcache.c | 15 ++++++++++++---
gdb/testsuite/gdb.base/maint.exp | 24 +++++++++++++++---------
3 files changed, 27 insertions(+), 17 deletions(-)
Index: src/gdb/regcache.c
===================================================================
--- src.orig/gdb/regcache.c 2011-04-20 17:44:27.556406002 +0100
+++ src/gdb/regcache.c 2011-04-20 17:51:26.826406002 +0100
@@ -453,16 +453,25 @@ get_thread_arch_regcache (ptid_t ptid, s
{
struct regcache_list *list;
struct regcache *new_regcache;
+ struct address_space *aspace;
for (list = current_regcache; list; list = list->next)
if (ptid_equal (list->regcache->ptid, ptid)
&& get_regcache_arch (list->regcache) == gdbarch)
return list->regcache;
- new_regcache = regcache_xmalloc_1 (gdbarch,
- target_thread_address_space (ptid), 0);
+ /* For the benefit of "maint print registers" & co when debugging an
+ executable, allow dumping the regcache even when there is no
+ thread selected (target_thread_address_space internal-errors if
+ no address space is found). Note that normal user commands will
+ fail higher up on the call stack due to no
+ target_has_registers. */
+ aspace = (ptid_equal (null_ptid, ptid)
+ ? NULL
+ : target_thread_address_space (ptid));
+
+ new_regcache = regcache_xmalloc_1 (gdbarch, aspace, 0);
new_regcache->ptid = ptid;
- gdb_assert (new_regcache->aspace != NULL);
list = xmalloc (sizeof (struct regcache_list));
list->regcache = new_regcache;
Index: src/gdb/infrun.c
===================================================================
--- src.orig/gdb/infrun.c 2011-04-20 17:44:27.556406002 +0100
+++ src/gdb/infrun.c 2011-04-20 17:51:26.836406002 +0100
@@ -6696,11 +6696,6 @@ ptid_is_pid (ptid_t ptid)
int
ptid_match (ptid_t ptid, ptid_t filter)
{
- /* Since both parameters have the same type, prevent easy mistakes
- from happening. */
- gdb_assert (!ptid_equal (ptid, minus_one_ptid)
- && !ptid_equal (ptid, null_ptid));
-
if (ptid_equal (filter, minus_one_ptid))
return 1;
if (ptid_is_pid (filter)
Index: src/gdb/testsuite/gdb.base/maint.exp
===================================================================
--- src.orig/gdb/testsuite/gdb.base/maint.exp 2011-04-20 17:44:27.556406002 +0100
+++ src/gdb/testsuite/gdb.base/maint.exp 2011-04-20 17:59:45.856406001 +0100
@@ -54,10 +54,6 @@ if $tracelevel then {
global usestubs
-#
-# test running programs
-#
-
set testfile "break"
set srcfile ${testfile}.c
set srcfile1 ${testfile}1.c
@@ -82,6 +78,21 @@ if { [gdb_compile "${binfile}0.o ${binf
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
+
+# The commands we test here produce many lines of output; disable "press
+# <return> to continue" prompts.
+gdb_test_no_output "set height 0"
+
+# Tests that require that no program is running
+
+gdb_file_cmd ${binfile}
+
+# Test for a regression where this command would internal-error if the
+# program wasn't running.
+gdb_test "maint print registers" "Name.*Nr.*Rel.*Offset.*Size.*Type.*"
+
+# Tests that can or should be done with a running program
+
gdb_load ${binfile}
if ![runto_main] then {
@@ -89,11 +100,6 @@ if ![runto_main] then {
}
-# The commands we test here produce many lines of output; disable "press
-# <return> to continue" prompts.
-gdb_test_no_output "set height 0"
-
-
#
# this command does not produce any output
# unless there is some problem with the symtabs and psymtabs