This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Minor cleanup of demangle code


Hi.

This patch is a minor cleanup of the demangler support.
It basically does two things:
- consolidates declarations of global demangle.c entities in gdb-demangle.h
  [I can't use demangle.h because libiberty uses the name.]
- moves the demangle support in utils.c to demangle.c

I will check this in in a few days if there are no objections.

Regression tested on amd64-linux.

2011-11-05  Doug Evans  <dje@google.com>

	* defs.h (is_cplus_marker, set_demangling_style): Moved to ...
	* gdb-demangle.h: ... here.  New file.
	* demangle.c: #include "gdb-demangle.h".
	(_initialize_demangler): Use initialize_file_ftype for prototype.
	Move "set demangle" and "set asm-demangle" parameters here from utils.c
	(demangle, show_demangle, asm_demangle, show_asm_demangle): Move here
	from utils.c
	* utils.c: Update. #include "gdb-demangle.h".
	* symtab.h (asm_demangle): Delete.
	(demangle): Move declaration next to use.
	* breakpoint.c: #include "gdb-demangle.h" instead of "demangle.h".
	* dwarf2read.c: #include "gdb-demangle.h".
	* gnu-v2-abi.c: Ditto.
	* jv-typeprint.c: Ditto.
	* mdebugread.c: Ditto.
	* p-typeprint.c: Ditto.
	* stabsread.c: Ditto.
	* printcmd.c: Ditto.
	(asm_demangle): Delete declaration.
	* tui/tui-stack.c: #include "gdb-demangle.h".

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.617
diff -u -p -r1.617 breakpoint.c
--- breakpoint.c	1 Nov 2011 14:51:20 -0000	1.617
+++ breakpoint.c	5 Nov 2011 20:43:56 -0000
@@ -38,7 +38,7 @@
 #include "target.h"
 #include "language.h"
 #include "gdb_string.h"
-#include "demangle.h"
+#include "gdb-demangle.h"
 #include "filenames.h"
 #include "annotate.h"
 #include "symfile.h"
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.304
diff -u -p -r1.304 defs.h
--- defs.h	14 Oct 2011 07:55:26 -0000	1.304
+++ defs.h	5 Nov 2011 20:43:56 -0000
@@ -149,9 +149,6 @@ typedef bfd_vma CORE_ADDR;
 
 #include "ptid.h"
 
-/* Check if a character is one of the commonly used C++ marker characters.  */
-extern int is_cplus_marker (int);
-
 /* Enable xdb commands if set.  */
 extern int xdb_commands;
 
@@ -442,10 +439,6 @@ extern struct cleanup *make_bpstat_clear
 
 extern int producer_is_gcc_ge_4 (const char *producer);
 
-/* From demangle.c */
-
-extern void set_demangling_style (char *);
-
 
 /* Annotation stuff.  */
 
Index: demangle.c
===================================================================
RCS file: /cvs/src/src/gdb/demangle.c,v
retrieving revision 1.27
diff -u -p -r1.27 demangle.c
--- demangle.c	7 Jan 2011 19:36:15 -0000	1.27
+++ demangle.c	5 Nov 2011 20:43:56 -0000
@@ -28,6 +28,7 @@
 #include "command.h"
 #include "gdbcmd.h"
 #include "demangle.h"
+#include "gdb-demangle.h"
 #include "gdb_string.h"
 
 /* Select the default C++ demangling style to use.  The default is "auto",
@@ -42,7 +43,31 @@
 #define DEFAULT_DEMANGLING_STYLE AUTO_DEMANGLING_STYLE_STRING
 #endif
 
-extern void _initialize_demangler (void);
+/* See documentation in gdb-demangle.h.  */
+int demangle = 1;
+
+static void
+show_demangle (struct ui_file *file, int from_tty,
+	       struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file,
+		    _("Demangling of encoded C++/ObjC names "
+		      "when displaying symbols is %s.\n"),
+		    value);
+}
+
+/* See documentation in gdb-demangle.h.  */
+int asm_demangle = 0;
+
+static void
+show_asm_demangle (struct ui_file *file, int from_tty,
+		   struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file,
+		    _("Demangling of C++/ObjC names in "
+		      "disassembly listings is %s.\n"),
+		    value);
+}
 
 /* String name for the current demangling style.  Set by the
    "set demangle-style" command, printed as part of the output by the
@@ -62,9 +87,6 @@ show_demangling_style_names(struct ui_fi
 		    value);
 }
 
-
-static void set_demangling_command (char *, int, struct cmd_list_element *);
-
 /* Set current demangling style.  Called by the "set demangle-style"
    command after it has updated the current_demangling_style_string to
    match what the user has entered.
@@ -142,7 +164,7 @@ set_demangling_command (char *ignore, in
     }
 }
 
-/* Fake a "set demangle-style" command.  */
+/* See documentation in gdb-demangle.h.  */
 
 void
 set_demangling_style (char *style)
@@ -168,12 +190,16 @@ set_demangling_style (char *style)
 
 static char cplus_markers[] = {'$', '.', '\0'};
 
+/* See documentation in gdb-demangle.h.  */
+
 int
 is_cplus_marker (int c)
 {
   return c && strchr (cplus_markers, c) != NULL;
 }
 
+extern initialize_file_ftype _initialize_demangler; /* -Wmissing-prototypes */
+
 void
 _initialize_demangler (void)
 {
@@ -191,6 +217,20 @@ _initialize_demangler (void)
     demangling_style_names[i] =
       xstrdup (libiberty_demanglers[i].demangling_style_name);
 
+  add_setshow_boolean_cmd ("demangle", class_support, &demangle, _("\
+Set demangling of encoded C++/ObjC names when displaying symbols."), _("\
+Show demangling of encoded C++/ObjC names when displaying symbols."), NULL,
+			   NULL,
+			   show_demangle,
+			   &setprintlist, &showprintlist);
+
+  add_setshow_boolean_cmd ("asm-demangle", class_support, &asm_demangle, _("\
+Set demangling of C++/ObjC names in disassembly listings."), _("\
+Show demangling of C++/ObjC names in disassembly listings."), NULL,
+			   NULL,
+			   show_asm_demangle,
+			   &setprintlist, &showprintlist);
+
   /* FIXME: cagney/2005-02-20: The code implementing this variable are
      malloc-ing and free-ing current_demangling_style_string when it
      should instead just point to an element of
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.578
diff -u -p -r1.578 dwarf2read.c
--- dwarf2read.c	20 Oct 2011 23:13:01 -0000	1.578
+++ dwarf2read.c	5 Nov 2011 20:43:56 -0000
@@ -34,6 +34,7 @@
 #include "dwarf2.h"
 #include "buildsym.h"
 #include "demangle.h"
+#include "gdb-demangle.h"
 #include "expression.h"
 #include "filenames.h"	/* for DOSish file names */
 #include "macrotab.h"
Index: gdb-demangle.h
===================================================================
RCS file: gdb-demangle.h
diff -N gdb-demangle.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb-demangle.h	5 Nov 2011 20:43:56 -0000
@@ -0,0 +1,37 @@
+/* Basic C++ demangling support for GDB.
+   Copyright (c) 2011 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_DEMANGLE_H
+#define GDB_DEMANGLE_H
+
+/* Nonzero means that encoded C++/ObjC names should be printed out in their
+   C++/ObjC form rather than raw.  */
+extern int demangle;
+
+/* Nonzero means that encoded C++/ObjC names should be printed out in their
+   C++/ObjC form even in assembler language displays.  If this is set, but
+   DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls.  */
+extern int asm_demangle;
+
+/* Fake a "set demangle-style" command.  */
+extern void set_demangling_style (char *);
+
+/* Check if a character is one of the commonly used C++ marker characters.  */
+extern int is_cplus_marker (int);
+
+#endif /* GDB_DEMANGLE_H */
Index: gnu-v2-abi.c
===================================================================
RCS file: /cvs/src/src/gdb/gnu-v2-abi.c,v
retrieving revision 1.41
diff -u -p -r1.41 gnu-v2-abi.c
--- gnu-v2-abi.c	14 Feb 2011 11:35:45 -0000	1.41
+++ gnu-v2-abi.c	5 Nov 2011 20:43:56 -0000
@@ -26,6 +26,7 @@
 #include "gdbtypes.h"
 #include "value.h"
 #include "demangle.h"
+#include "gdb-demangle.h"
 #include "cp-abi.h"
 #include "cp-support.h"
 #include "exceptions.h"
Index: jv-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-typeprint.c,v
retrieving revision 1.23
diff -u -p -r1.23 jv-typeprint.c
--- jv-typeprint.c	18 May 2011 16:30:35 -0000	1.23
+++ jv-typeprint.c	5 Nov 2011 20:43:56 -0000
@@ -23,6 +23,7 @@
 #include "gdbtypes.h"
 #include "value.h"
 #include "demangle.h"
+#include "gdb-demangle.h"
 #include "jv-lang.h"
 #include "gdb_string.h"
 #include "typeprint.h"
Index: mdebugread.c
===================================================================
RCS file: /cvs/src/src/gdb/mdebugread.c,v
retrieving revision 1.125
diff -u -p -r1.125 mdebugread.c
--- mdebugread.c	14 Jun 2011 18:53:14 -0000	1.125
+++ mdebugread.c	5 Nov 2011 20:43:56 -0000
@@ -52,6 +52,7 @@
 #include "stabsread.h"
 #include "complaints.h"
 #include "demangle.h"
+#include "gdb-demangle.h"
 #include "gdb_assert.h"
 #include "block.h"
 #include "dictionary.h"
Index: p-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/p-typeprint.c,v
retrieving revision 1.41
diff -u -p -r1.41 p-typeprint.c
--- p-typeprint.c	18 May 2011 16:30:36 -0000	1.41
+++ p-typeprint.c	5 Nov 2011 20:43:56 -0000
@@ -31,7 +31,7 @@
 #include "language.h"
 #include "p-lang.h"
 #include "typeprint.h"
-
+#include "gdb-demangle.h"
 #include "gdb_string.h"
 #include <errno.h>
 #include <ctype.h>
Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.199
diff -u -p -r1.199 printcmd.c
--- printcmd.c	9 Oct 2011 19:38:29 -0000	1.199
+++ printcmd.c	5 Nov 2011 20:43:56 -0000
@@ -32,6 +32,7 @@
 #include "target.h"
 #include "breakpoint.h"
 #include "demangle.h"
+#include "gdb-demangle.h"
 #include "valprint.h"
 #include "annotate.h"
 #include "symfile.h"		/* for overlay functions */
@@ -62,9 +63,6 @@
 # define USE_PRINTF_I64 0
 #endif
 
-extern int asm_demangle;	/* Whether to demangle syms in asm
-				   printouts.  */
-
 struct format_data
   {
     int count;
Index: stabsread.c
===================================================================
RCS file: /cvs/src/src/gdb/stabsread.c,v
retrieving revision 1.139
diff -u -p -r1.139 stabsread.c
--- stabsread.c	20 Oct 2011 20:06:14 -0000	1.139
+++ stabsread.c	5 Nov 2011 20:43:56 -0000
@@ -41,6 +41,7 @@
 #include "buildsym.h"
 #include "complaints.h"
 #include "demangle.h"
+#include "gdb-demangle.h"
 #include "language.h"
 #include "doublest.h"
 #include "cp-abi.h"
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gdb/symtab.h,v
retrieving revision 1.190
diff -u -p -r1.190 symtab.h
--- symtab.h	9 Oct 2011 19:34:18 -0000	1.190
+++ symtab.h	5 Nov 2011 20:43:56 -0000
@@ -244,11 +244,14 @@ extern char *symbol_demangled_name (cons
    name if demangle is on and the "mangled" form of the name if
    demangle is off.  In other languages this is just the symbol name.
    The result should never be NULL.  Don't use this for internal
-   purposes (e.g. storing in a hashtable): it's only suitable for
-   output.  */
+   purposes (e.g. storing in a hashtable): it's only suitable for output.
+
+   N.B. symbol may be anything with a ginfo member,
+   e.g., struct symbol or struct minimal_symbol.  */
 
 #define SYMBOL_PRINT_NAME(symbol)					\
   (demangle ? SYMBOL_NATURAL_NAME (symbol) : SYMBOL_LINKAGE_NAME (symbol))
+extern int demangle;
 
 /* Macro that tests a symbol for a match against a specified name string.
    First test the unencoded name, then looks for and test a C++ encoded
@@ -866,10 +869,6 @@ struct symtab
 
 extern int currently_reading_symtab;
 
-/* From utils.c.  */
-extern int demangle;
-extern int asm_demangle;
-
 /* symtab.c lookup functions */
 
 extern const char multiple_symbols_ask[];
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.265
diff -u -p -r1.265 utils.c
--- utils.c	4 Nov 2011 16:45:12 -0000	1.265
+++ utils.c	5 Nov 2011 20:43:56 -0000
@@ -50,7 +50,7 @@
 #include "serial.h"
 #include "bfd.h"
 #include "target.h"
-#include "demangle.h"
+#include "gdb-demangle.h"
 #include "expression.h"
 #include "language.h"
 #include "charset.h"
@@ -138,35 +138,6 @@ int quit_flag;
 
 int immediate_quit;
 
-/* Nonzero means that encoded C++/ObjC names should be printed out in their
-   C++/ObjC form rather than raw.  */
-
-int demangle = 1;
-static void
-show_demangle (struct ui_file *file, int from_tty,
-	       struct cmd_list_element *c, const char *value)
-{
-  fprintf_filtered (file,
-		    _("Demangling of encoded C++/ObjC names "
-		      "when displaying symbols is %s.\n"),
-		    value);
-}
-
-/* Nonzero means that encoded C++/ObjC names should be printed out in their
-   C++/ObjC form even in assembler language displays.  If this is set, but
-   DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls.  */
-
-int asm_demangle = 0;
-static void
-show_asm_demangle (struct ui_file *file, int from_tty,
-		   struct cmd_list_element *c, const char *value)
-{
-  fprintf_filtered (file,
-		    _("Demangling of C++/ObjC names in "
-		      "disassembly listings is %s.\n"),
-		    value);
-}
-
 /* Nonzero means that strings with character values >0x7F should be printed
    as octal escapes.  Zero means just print the value (e.g. it's an
    international character, and the terminal or window can cope.)  */
@@ -2864,13 +2835,6 @@ Show number of lines gdb thinks are in a
 
   init_page_info ();
 
-  add_setshow_boolean_cmd ("demangle", class_support, &demangle, _("\
-Set demangling of encoded C++/ObjC names when displaying symbols."), _("\
-Show demangling of encoded C++/ObjC names when displaying symbols."), NULL,
-			   NULL,
-			   show_demangle,
-			   &setprintlist, &showprintlist);
-
   add_setshow_boolean_cmd ("pagination", class_support,
 			   &pagination_enabled, _("\
 Set state of pagination."), _("\
@@ -2895,13 +2859,6 @@ Show printing of 8-bit characters in str
 			   show_sevenbit_strings,
 			   &setprintlist, &showprintlist);
 
-  add_setshow_boolean_cmd ("asm-demangle", class_support, &asm_demangle, _("\
-Set demangling of C++/ObjC names in disassembly listings."), _("\
-Show demangling of C++/ObjC names in disassembly listings."), NULL,
-			   NULL,
-			   show_asm_demangle,
-			   &setprintlist, &showprintlist);
-
   add_setshow_boolean_cmd ("timestamp", class_maintenance,
 			    &debug_timestamp, _("\
 Set timestamping of debugging messages."), _("\
Index: tui/tui-stack.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tui-stack.c,v
retrieving revision 1.42
diff -u -p -r1.42 tui-stack.c
--- tui/tui-stack.c	29 Aug 2011 16:55:16 -0000	1.42
+++ tui/tui-stack.c	5 Nov 2011 20:43:56 -0000
@@ -28,6 +28,7 @@
 #include "inferior.h"
 #include "target.h"
 #include "top.h"
+#include "gdb-demangle.h"
 #include "gdb_string.h"
 #include "tui/tui.h"
 #include "tui/tui-data.h"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]