Patch implementing GDB/MI -symbol-info-symbol command

Lluis xscript@gmx.net
Tue Feb 21 20:46:00 GMT 2006


Hello all,

Attached is a patch implementing the GDB/MI command '-symbol-info-symbol', 
but a few words are to be said about it:

- I'm not sure if I did all the memory management right (aka, the gdb way)

- If no symbol is found by that address, an error is thrown (but it could 
  return an empty result list otherwise, as you wish, although I've used 
  the same behaviour that the "info symbol" command has)

- I've turned a pair of "special" conditions from the original "info 
  symbol" command to errors, as I'm not sure of what should they output 
  ("load address range of" & "{mapped,unmapped} overlay")

- The output is first precalculated, saving it on xrealloc'ed memory, to be 
  able to first output a counter of the number of results (followed by a 
  list of the results, as you can see on the doc example), if this counter 
  is not found to be usefull, it can be thrown away and the command should 
  be a little faster

- I'm not sure if, in case of error, I have to use the error() function, or 
  the mi_error_message + return form (this is the one I've taken, like in 
  mi-main.c)

- I'm not sure if the error messages should be translatable or not

Well, I think that's all I had to say, if you have any comments or 
corrections, please send a mail directly to me, as I'm not subscribed to 
this list.

Thanks,
  Lluis

-- 
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
-------------- next part --------------
Index: gdb/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.7606
diff -u -r1.7606 ChangeLog
--- gdb/ChangeLog	21 Feb 2006 19:46:47 -0000	1.7606
+++ gdb/ChangeLog	21 Feb 2006 20:36:55 -0000
@@ -1,3 +1,9 @@
+2006-02-21  Lluis Vilanova  <xscript@gmx.net>
+
+	* mi/mi-cmds.c, mi/mi-cmds.h, mi/mi-symbol-cmds.c: Implement
+	mi_cmd_symbol_info_symbol.
+	* doc/gdb.texinfo: Add example for -symbol-info-symbol GDB/MI command.
+
 2006-02-21  Andrew Stubbs  <andrew.stubbs@st.com>
 
 	* defs.h (directory_switch): Add prototype.
Index: gdb/doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.314
diff -u -r1.314 gdb.texinfo
--- gdb/doc/gdb.texinfo	18 Feb 2006 20:45:01 -0000	1.314
+++ gdb/doc/gdb.texinfo	21 Feb 2006 20:37:33 -0000
@@ -17068,8 +17068,8 @@
 
 @heading Acknowledgments
 
-In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
-Elena Zannoni.
+In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs,
+Lluis Vilanova and Elena Zannoni.
 
 @menu
 * GDB/MI Command Syntax::
@@ -20149,7 +20149,12 @@
 The corresponding @value{GDBN} command is @samp{info symbol}.
 
 @subsubheading Example
-N.A.
+@smallexample
+(@value{GDBP})
+-symbol-info-symbol 0xc03ce892
+^done,count="1",symbols=[@{name="serio_pid",offset="2",section=".bss"@}]
+(@value{GDBP})
+@end smallexample
 
 
 @subheading The @code{-symbol-list-functions} Command
Index: gdb/mi/mi-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.c,v
retrieving revision 1.20
diff -u -r1.20 mi-cmds.c
--- gdb/mi/mi-cmds.c	23 Dec 2005 18:57:46 -0000	1.20
+++ gdb/mi/mi-cmds.c	21 Feb 2006 20:37:33 -0000
@@ -119,7 +119,7 @@
   { "symbol-info-file", { NULL, 0 }, NULL, NULL },
   { "symbol-info-function", { NULL, 0 }, NULL, NULL },
   { "symbol-info-line", { NULL, 0 }, NULL, NULL },
-  { "symbol-info-symbol", { NULL, 0 }, NULL, NULL },
+  { "symbol-info-symbol", { NULL, 0 }, NULL, mi_cmd_symbol_info_symbol},
   { "symbol-list-functions", { NULL, 0 }, NULL, NULL },
   { "symbol-list-lines", { NULL, 0 }, 0, mi_cmd_symbol_list_lines},
   { "symbol-list-types", { NULL, 0 }, NULL, NULL },
Index: gdb/mi/mi-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
retrieving revision 1.19
diff -u -r1.19 mi-cmds.h
--- gdb/mi/mi-cmds.h	23 Dec 2005 18:57:46 -0000	1.19
+++ gdb/mi/mi-cmds.h	21 Feb 2006 20:37:33 -0000
@@ -98,6 +98,7 @@
 extern mi_cmd_argv_ftype mi_cmd_stack_list_frames;
 extern mi_cmd_argv_ftype mi_cmd_stack_list_locals;
 extern mi_cmd_argv_ftype mi_cmd_stack_select_frame;
+extern mi_cmd_argv_ftype mi_cmd_symbol_info_symbol;
 extern mi_cmd_argv_ftype mi_cmd_symbol_list_lines;
 extern mi_cmd_args_ftype mi_cmd_target_download;
 extern mi_cmd_args_ftype mi_cmd_target_select;
Index: gdb/mi/mi-symbol-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-symbol-cmds.c,v
retrieving revision 1.3
diff -u -r1.3 mi-symbol-cmds.c
--- gdb/mi/mi-symbol-cmds.c	23 Dec 2005 18:57:46 -0000	1.3
+++ gdb/mi/mi-symbol-cmds.c	21 Feb 2006 20:37:33 -0000
@@ -22,6 +22,89 @@
 #include "mi-cmds.h"
 #include "symtab.h"
 #include "ui-out.h"
+#include "value.h"
+#include "objfiles.h"
+
+/* SYMBOL-INFO-SYMBOL:
+ 
+   ADDR: address to look up.
+
+   Describe what symbol is at location ADDR. */
+
+enum mi_cmd_result
+mi_cmd_symbol_info_symbol (char *command, char **argv, int argc)
+{
+  struct minimal_symbol *msymbol;
+  struct objfile *objfile;
+  struct obj_section *osect;
+  asection *sect;
+  CORE_ADDR addr, sect_addr;
+  int matches = 0, i;
+  unsigned int offset;
+  struct cleanup *cleanup_list_symbols, *cleanup_tuple_symbol;
+  char **sym_name = NULL;
+  int *sym_offs = NULL;
+  char **sym_sect = NULL;
+
+  if (argc != 1)
+  {
+    mi_error_message = xstrprintf (_("mi_cmd_symbol_info_symbol: Usage: ADDR."));
+    return MI_CMD_ERROR;
+  }
+
+  addr = parse_and_eval_address (argv[0]);
+
+  ALL_OBJSECTIONS (objfile, osect)
+  {
+    sect = osect->the_bfd_section;
+    sect_addr = overlay_mapped_address (addr, sect);
+
+    if (osect->addr <= sect_addr && sect_addr < osect->endaddr &&
+        (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, sect)))
+    {
+      offset = sect_addr - SYMBOL_VALUE_ADDRESS (msymbol);
+      sym_name = xrealloc(sym_name, sizeof(*sym_name) * (matches + 1));
+      sym_offs = xrealloc(sym_offs, sizeof(*sym_offs) * (matches + 1));
+      sym_sect = xrealloc(sym_sect, sizeof(*sym_sect) * (matches + 1));
+      sym_name[matches] = SYMBOL_PRINT_NAME (msymbol);
+      sym_offs[matches] = offset;
+      if (pc_in_unmapped_range (addr, sect))
+      {
+        mi_error_message = xstrprintf ("mi_cmd_symbol_info_symbol: load address range of");
+        return MI_CMD_ERROR;
+      }
+      if (section_is_overlay (sect))
+      {
+        mi_error_message = xstrprintf ("mi_cmd_symbol_info_symbol: %s overlay",
+            section_is_mapped (sect) ? "mapped" : "unmapped");
+        return MI_CMD_ERROR;
+      }
+      sym_sect[matches] = sect->name;
+      matches++;
+    }
+  }
+  if (matches == 0)
+  {
+    mi_error_message = xstrprintf (_("mi_cmd_symbol_info_symbol: No symbol matches %s.\n"), argv[0]);
+    return MI_CMD_ERROR;
+  }
+
+  make_cleanup (xfree, sym_name);
+  make_cleanup (xfree, sym_offs);
+  make_cleanup (xfree, sym_sect);
+  ui_out_field_int (uiout, "count", matches);
+  cleanup_list_symbols = make_cleanup_ui_out_list_begin_end (uiout, "symbols");
+  for (i = 0; i < matches; i++)
+  {
+    cleanup_tuple_symbol = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+    ui_out_field_string (uiout, "name", sym_name[i]);
+    ui_out_field_int (uiout, "offset", sym_offs[i]);
+    ui_out_field_string (uiout, "section", sym_sect[i]);
+  }
+  do_cleanups (cleanup_list_symbols);
+
+  return MI_CMD_DONE;
+}
 
 /* SYMBOL-LIST-LINES:
 


More information about the Gdb-patches mailing list