[1/1] don't list typedef symbols in C++, d and ada

Message ID 1500096894-3947-1-git-send-email-zhouzhouyi@gmail.com
State New, archived
Headers

Commit Message

Zhouyi Zhou July 15, 2017, 5:34 a.m. UTC
  C++ "struct foo { ... }" also defines a typedef for "foo", in order
to make command like "gdb) ptype (foo *)0" work, function
symbol_matches_domain relaxes the check for domain check for cplus,
d and ada.

However the command "list foo" will invoke symbol_matches_domain,
which results in odd result when execute command "list foo".

For example, consider debugging following program.
struct foo {
        int i;
};

int foo(void);

int main()
{
        struct foo l;
        return foo();
}

int foo() {
        return 0;
}

(gdb) list foo
file: "example.c", line number: 1
file: "example.c", line number: 13

Following patch get rid of "non var" symbols in function
find_function_symbols. 

Tested on x86-64 GNU/Linux. 
Signed-off-by: Zhouyi Zhou <zhouzhouyi@gmail.com>

gdb/ChangeLog:
2017-07-15 Zhouyi Zhou <zhouzhouyi@gmail.com>
	* linespec.c (find_function_symbols): remove non-var symbols
	from the matching result.
---
 gdb/linespec.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 4c076fe..4876a73 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3223,6 +3223,8 @@  find_function_symbols (struct linespec_state *state,
 {
   struct collect_info info;
   VEC (const_char_ptr) *symbol_names = NULL;
+  int ix;
+  struct symbol *sym;
   struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
 					  &symbol_names);
 
@@ -3240,7 +3242,14 @@  find_function_symbols (struct linespec_state *state,
     add_matching_symbols_to_info (name, &info, state->search_pspace);
 
   do_cleanups (cleanup);
-
+  
+  for (ix = 0; VEC_iterate (symbolp, info.result.symbols, ix, sym); ++ix)
+    {
+      if (sym->domain != VAR_DOMAIN)
+	VEC_unordered_remove (symbolp,
+			      info.result.symbols, ix);
+    }
+  
   if (VEC_empty (symbolp, info.result.symbols))
     {
       VEC_free (symbolp, info.result.symbols);