public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix number of children of varobj with stub debug info
@ 2022-06-21  8:18 Christian Walther
  2022-06-21 14:24 ` Bruno Larsen
  0 siblings, 1 reply; 8+ messages in thread
From: Christian Walther @ 2022-06-21  8:18 UTC (permalink / raw)
  To: gdb-patches; +Cc: Christian Walther

GDB under some circumstances wrongly reports 'numchild="0"' on a
variable object for a pointer to a C++ class instance when the type
description from the debug info is a stub that does not include members.
The code path is missing a call to check_typedef() to look up the
complete type description. This commit adds it.

Additional conditions for the bug to occur:
1. "print object" is set to "on"
2. The class has no run-time type identification (no vtable).

Debug information of this kind is generated by Clang 13.
---

Note: I am not certain whether this is the best place to insert the
missing call, or whether placing it somewhere else would benefit other
code paths too. It does fix my particular problem where I put it.


Steps to reproduce:

1. Create the following three files:

main.cpp
----------------
#include <cstdio>
#include "c.h"

extern "C" int main(int argc, char** argv) {
	C* c = new C(5);
	printf("Hello World! %d\n", c->getX());
	return 0;
}
----------------

c.h
----------------
class C {
	public:
		C(int ax);
		int getX();
	private:
		int x;
};
----------------

c.cpp
----------------
#include "c.h"

C::C(int ax) : x(ax) {}

int C::getX() {
	return x;
}
----------------

2. Compile them with Clang 13:

clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/clang++ -g -O0 -c -o main.o main.cpp
clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/clang++ -g -O0 -c -o c.o c.cpp
clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/clang++ -g -o mini main.o c.o

3. Verify that the debug information of main.o only contains a stub
definition of class C that does not include member x:

readelf --debug-dump=info main.o

It should look roughly like this and not contain any DW_TAG_member:

 <1><690>: Abbrev Number: 23 (DW_TAG_class_type)
    <691>   DW_AT_name        : (indirect string, offset: 0x265): C
    <695>   DW_AT_declaration : 1

(I have not been able to reproduce this with
clang+llvm-12.0.1-x86_64-linux-gnu-ubuntu-16.04, which generates a full
definition, and clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04, which
generates invalid debug info.)

4. Debug:

gdb --interpreter mi2 --args mini
-break-insert main.cpp:6
-gdb-set print object on
-exec-run
-var-create - * c
-gdb-exit

Expected result:

^done,name="var1",numchild="1",value="0x...",type="C *",thread-id="1",has_more="0"

Actual result:

^done,name="var1",numchild="0",value="0x...",type="C *",thread-id="1",has_more="0"

---
 gdb/c-varobj.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index 8fecbd57e08..0c0b1abe968 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -121,6 +121,7 @@ adjust_value_for_child_access (struct value **value,
       enclosing_type = value_actual_type (*value, 1, &real_type_found);
       if (real_type_found)
 	{
+	  enclosing_type = check_typedef(enclosing_type);
 	  *type = enclosing_type;
 	  *value = value_cast (enclosing_type, *value);
 	}
-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-25 12:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21  8:18 [PATCH] Fix number of children of varobj with stub debug info Christian Walther
2022-06-21 14:24 ` Bruno Larsen
2022-06-22 12:58   ` Christian Walther
2022-06-22 13:40     ` Bruno Larsen
2022-06-22 15:37       ` [PATCH v2 1/2] " Christian Walther
2022-06-22 15:37         ` [PATCH v2 2/2] Move a comment to a less confusing place Christian Walther
2022-07-25 12:52         ` [PING][PATCH v2 1/2] Fix number of children of varobj with stub debug info Christian Walther
2022-06-22 15:43       ` [PATCH] " Christian Walther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).