+2015-01-11 Doug Evans <xdje42@gmail.com>
+
+ PR gdb/15830
+ * NEWS: The "maint demangle" command is renamed as "demangle".
+ * demangle.c: #include cli/cli-utils.h, language.h.
+ (demangle_command): New function.
+ (_initialize_demangle): Add new command "demangle".
+ * maint.c (maintenance_demangle): Stub out.
+ (_initialize_maint_cmds): Update help text for "maint demangle",
+ and mark as deprecated.
+
2015-01-11 Mark Kettenis <kettenis@gnu.org>
* inf-ptrace.c (inf_ptrace_follow_fork): Adjust now that
* New commands
+demangle [-l language] [--] name
+ Demangle "name" in the specified language, or the current language
+ if elided. This command is renamed from the "maint demangle" command.
+ The latter is kept as a no-op to avoid "maint demangle" being interpreted
+ as "maint demangler-warning".
+
queue-signal signal-name-or-number
Queue a signal to be delivered to the thread when it is resumed.
to a styles of demangling, and GDB specific. */
#include "defs.h"
+#include "cli/cli-utils.h" /* for skip_to_space */
#include "command.h"
#include "gdbcmd.h"
#include "demangle.h"
#include "gdb-demangle.h"
+#include "language.h"
+
/* Select the default C++ demangling style to use. The default is "auto",
which allows gdb to attempt to pick an appropriate demangling style for
the executable it has loaded. It can be set to a specific style ("gnu",
#define DEFAULT_DEMANGLING_STYLE AUTO_DEMANGLING_STYLE_STRING
#endif
+static void demangle_command (char *, int);
+
/* See documentation in gdb-demangle.h. */
int demangle = 1;
return c && strchr (cplus_markers, c) != NULL;
}
+/* Demangle the given string in the current language. */
+
+static void
+demangle_command (char *args, int from_tty)
+{
+ char *demangled, *name, *lang_name = NULL;
+ char *arg_buf, *arg_start;
+ int processing_args = 1;
+ const struct language_defn *lang;
+ struct cleanup *cleanups;
+
+ arg_buf = xstrdup (args != NULL ? args : "");
+ cleanups = make_cleanup (xfree, arg_buf);
+ arg_start = arg_buf;
+
+ while (processing_args
+ && *arg_start == '-')
+ {
+ char *p = skip_to_space (arg_start);
+
+ if (strncmp (arg_start, "-l", p - arg_start) == 0)
+ {
+ char *lang_name_end;
+
+ lang_name = skip_spaces (p);
+ lang_name_end = skip_to_space (lang_name);
+ lang_name = savestring (lang_name, lang_name_end - lang_name);
+ make_cleanup (xfree, lang_name);
+ p = lang_name_end;
+ }
+ else if (strncmp (arg_start, "--", p - arg_start) == 0)
+ processing_args = 0;
+ else
+ {
+ *p = '\0';
+ error (_("Unrecognized option '%s' to demangle command. "
+ "Try \"help demangle\"."), arg_start);
+ }
+
+ arg_start = skip_spaces (p);
+ }
+
+ name = arg_start;
+
+ if (*name == '\0')
+ error (_("Usage: demangle [-l language] [--] name"));
+
+ if (lang_name != NULL)
+ {
+ enum language lang_enum;
+
+ lang_enum = language_enum (lang_name);
+ if (lang_enum == language_unknown)
+ error (_("Unknown language \"%s\""), lang_name);
+ lang = language_def (lang_enum);
+ }
+ else
+ lang = current_language;
+
+ demangled = language_demangle (lang, name, DMGL_ANSI | DMGL_PARAMS);
+ if (demangled != NULL)
+ {
+ printf_filtered ("%s\n", demangled);
+ xfree (demangled);
+ }
+ else
+ error (_("Can't demangle \"%s\""), name);
+
+ do_cleanups (cleanups);
+}
+
extern initialize_file_ftype _initialize_demangler; /* -Wmissing-prototypes */
void
set_demangling_command,
show_demangling_style_names,
&setlist, &showlist);
+
+ add_cmd ("demangle", class_support, demangle_command, _("\
+Demangle a mangled name.\n\
+Usage: demangle [-l language] [--] name\n\
+If LANGUAGE is not specified, NAME is demangled in the current language."),
+ &cmdlist);
}
+2015-01-11 Doug Evans <xdje42@gmail.com>
+
+ PR gdb/15830
+ * gdb.texinfo (Debugging C Plus Plus): Mention "demangle".
+ (Symbols): Ditto.
+ (Maintenance Commands): Delete docs for "maint demangle".
+
2015-01-10 Doug Evans <xdje42@gmail.com>
* gdb.texinfo (Symbols): Document new commands
one entry per virtual table; there may be multiple virtual tables when
multiple inheritance is in use.
+@cindex C@t{++} demangling
+@item demangle @var{name}
+Demangle @var{name}.
+@xref{Symbols}, for a more complete description of the @code{demangle} command.
+
@cindex C@t{++} symbol display
@item set print demangle
@itemx show print demangle
__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
@end smallexample
+@kindex demangle
+@cindex demangle
+@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
+Demangle @var{name}.
+If @var{language} is provided it is the name of the language to demangle
+@var{name} in. Otherwise @var{name} is demangled in the current language.
+
+The @samp{--} option specifies the end of options,
+and is useful when @var{name} begins with a dash.
+
+The parameter @code{demangle-style} specifies how to interpret the kind
+of mangling used. @xref{Print Settings}.
+
@kindex whatis
@item whatis[/@var{flags}] [@var{arg}]
Print the data type of @var{arg}, which can be either an expression
@item maint cplus namespace
Print the list of possible C@t{++} namespaces.
-@kindex maint demangle
-@item maint demangle @var{name}
-Demangle a C@t{++} or Objective-C mangled @var{name}.
-
@kindex maint deprecate
@kindex maint undeprecate
@cindex deprecated commands
demangler_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
}
-/* Someday we should allow demangling for things other than just
- explicit strings. For example, we might want to be able to specify
- the address of a string in either GDB's process space or the
- debuggee's process space, and have gdb fetch and demangle that
- string. If we have a char* pointer "ptr" that points to a string,
- we might want to be able to given just the name and have GDB
- demangle and print what it points to, etc. (FIXME) */
+/* Old command to demangle a string. The command has been moved to "demangle".
+ It is kept for now because otherwise "mt demangle" gets interpreted as
+ "mt demangler-warning" which artificially creates an internal gdb error. */
static void
maintenance_demangle (char *args, int from_tty)
{
- char *demangled;
-
- if (args == NULL || *args == '\0')
- {
- printf_unfiltered (_("\"maintenance demangle\" takes "
- "an argument to demangle.\n"));
- }
- else
- {
- demangled = language_demangle (current_language, args,
- DMGL_ANSI | DMGL_PARAMS);
- if (demangled != NULL)
- {
- printf_unfiltered ("%s\n", demangled);
- xfree (demangled);
- }
- else
- {
- printf_unfiltered (_("Can't demangle \"%s\"\n"), args);
- }
- }
+ printf_filtered (_("This command has been moved to \"demangle\".\n"));
}
static void
void
_initialize_maint_cmds (void)
{
+ struct cmd_list_element *cmd;
+
add_prefix_cmd ("maintenance", class_maintenance, maintenance_command, _("\
Commands for use by GDB maintainers.\n\
Includes commands to dump specific internal GDB structures in\n\
-a human readable form, to cause GDB to deliberately dump core,\n\
-to test internal functions such as the C++/ObjC demangler, etc."),
+a human readable form, to cause GDB to deliberately dump core, etc."),
&maintenancelist, "maintenance ", 0,
&cmdlist);
Cause GDB to behave as if a demangler warning was reported."),
&maintenancelist);
- add_cmd ("demangle", class_maintenance, maintenance_demangle, _("\
-Demangle a C++/ObjC mangled name.\n\
-Call internal GDB demangler routine to demangle a C++ link name\n\
-and prints the result."),
- &maintenancelist);
+ cmd = add_cmd ("demangle", class_maintenance, maintenance_demangle, _("\
+This command has been moved to \"demangle\"."),
+ &maintenancelist);
+ deprecate_cmd (cmd, "demangle");
add_prefix_cmd ("per-command", class_maintenance, set_per_command_cmd, _("\
Per-command statistics settings."),
+2015-01-11 Doug Evans <xdje42@gmail.com>
+
+ PR gdb/15830
+ * gdb.base/maint.exp: Remove references to "maint demangle".
+ * gdb.cp/demangle.exp: Update. "maint demangle" -> "demangle".
+ Add tests for explicitly specifying language to demangle.
+ * gdb.dlang/demangle.exp: Ditto.
+
2015-01-09 Pedro Alves <palves@redhat.com>
* gdb.threads/non-stop-fair-events.c: New file.
#maintenance expand-symtabs -- Expand symtabs matching a file regexp
#maintenance set -- Set GDB internal variables used by the GDB maintainer
#maintenance show -- Show GDB internal variables used by the GDB maintainer
-#maintenance demangle -- Demangle a C++ mangled name
#maintenance dump-me -- Get fatal error; make debugger dump its core
#maintenance print -- Maintenance command for printing GDB internal state
#maintenance info -- Commands for showing internal info about the program being debugged
"Command execution time: \[0-9.\]+ \\(cpu\\), \[0-9.\]+ \\(wall\\)\[\r\n\]+Space used: $decimal \\(\\+$decimal for this command\\)\[\r\n\]+#symtabs: $decimal \\(\\+$decimal\\), #compunits: $decimal \\(\\+$decimal\\), #blocks: $decimal \\(\\+$decimal\\)"
gdb_test_no_output "maint set per-command off"
-gdb_test "maint demangle" \
- "\"maintenance demangle\" takes an argument to demangle\\."
-
-gdb_test "maint demangle main" "Can't demangle \"main\""
-
-
-
# The timeout value is raised, because printing all the symbols and
# statistical information about Cygwin and Windows libraries takes a lot
# of time.
#============test help on maint commands
gdb_test "help maint" \
- "Commands for use by GDB maintainers\\..*Includes commands to dump specific internal GDB structures in.*a human readable form, to cause GDB to deliberately dump core,.*to test internal functions such as the C../ObjC demangler, etc\\..*List of maintenance subcommands:.*maintenance info.*maintenance internal-error.*maintenance print.*maintenance set.*maintenance show.*Type.*help maintenance.*followed by maintenance subcommand name for full documentation\\..*Command name abbreviations are allowed if unambiguous\\..*"
+ "Commands for use by GDB maintainers\\..*Includes commands to dump specific internal GDB structures in.*a human readable form, to cause GDB to deliberately dump core, etc\\..*List of maintenance subcommands:.*maintenance info.*maintenance internal-error.*maintenance print.*maintenance set.*maintenance show.*Type.*help maintenance.*followed by maintenance subcommand name for full documentation\\..*Command name abbreviations are allowed if unambiguous\\..*"
gdb_test "help maint info" \
"Commands for showing internal info about the program being debugged.*unambiguous\\..*"
test_prefix_command_help {"maint" "maintenance"} {
"Commands for use by GDB maintainers\\.\[\r\n\]+"
"Includes commands to dump specific internal GDB structures in\[\r\n\]+"
- "a human readable form, to cause GDB to deliberately dump core,\[\r\n\]+"
- "to test internal functions such as the C\\+\\+/ObjC demangler, etc\\.\[\r\n\]+"
+ "a human readable form, to cause GDB to deliberately dump core, etc\\.\[\r\n\]+"
}
#set oldtimeout $timeout
set_demangling_style $style
}
- $tester "maintenance demangle $name" $result $test
+ $tester "demangle $name" $result $test
}
### Demangle an identifier, and check that the result matches a pattern.
## 1999-04-19: "Fix from Dale Hawkins". Shouldn't segfault.
# Accept even a dubious demangling; the string is ambiguous.
- gdb_test_multiple "maintenance demangle __thunk_64__0RL__list__Q29CosNaming20_proxy_NamingContextUlRPt25_CORBA_Unbounded_Sequence1ZQ29CosNaming7BindingRPQ29CosNaming15BindingIterator" "gnu: __thunk_64__0RL__list__Q29CosNaming20_proxy_NamingContextUlRPt25_CORBA_Unbounded_Sequence1ZQ29CosNaming7BindingRPQ29CosNaming15BindingIterator" {
+ gdb_test_multiple "demangle __thunk_64__0RL__list__Q29CosNaming20_proxy_NamingContextUlRPt25_CORBA_Unbounded_Sequence1ZQ29CosNaming7BindingRPQ29CosNaming15BindingIterator" "gnu: __thunk_64__0RL__list__Q29CosNaming20_proxy_NamingContextUlRPt25_CORBA_Unbounded_Sequence1ZQ29CosNaming7BindingRPQ29CosNaming15BindingIterator" {
-re "virtual function thunk \\(delta:-64\\) for CosNaming::_proxy_NamingContext::_0RL__list\\(unsigned long, _CORBA_Unbounded_Sequence<CosNaming::Binding> \\*\\&, CosNaming::BindingIterator \\*\\&\\)\r\n$gdb_prompt $" {
pass "gnu: __thunk_64__0RL__list__Q29CosNaming20_proxy_NamingContextUlRPt25_CORBA_Unbounded_Sequence1ZQ29CosNaming7BindingRPQ29CosNaming15BindingIterator"
}
catch_demangling_errors test_gnu_style_demangling
catch_demangling_errors test_arm_style_demangling
catch_demangling_errors test_hp_style_demangling
+
+ # Verify specifying demangle language.
+ gdb_test_no_output "set language unknown"
+ set_demangling_style "auto"
+ gdb_test_exact "demangle -l c++ -- _ZSt4cout" "std::cout"
+ gdb_test_exact "demangle -l c++ _ZSt4cout" "std::cout"
+ gdb_test_exact "demangle -l c -- _ZSt4cout" "Can't demangle \"_ZSt4cout\""
+ gdb_test_exact "demangle -l garbage xyzdje" "Unknown language \"garbage\""
}
do_tests
### Utility function for test_demangling and test_demangling_exact.
proc test_demangling {test result} {
- gdb_test_exact "maintenance demangle $test" $result $test
+ gdb_test_exact "demangle $test" $result $test
}
proc test_d_demangling {} {
gdb_test_no_output "set width 0"
test_d_demangling
+
+ # Verify we can specify the d language to demangle.
+ gdb_test_exact "demangle -l d -- _Dmain" "D main"
} else {
warning "D demangling tests suppressed."
}