Skip to content

Commit 8618a7b

Browse files
author
Vladimir Uzelac
committed
libdemangle-msvc: use MSVC demangler in GDB
This is the fourth in a series of patches adding MSVC symbol demangling support to the GNU toolchain. Register the MSVC demangler via bfd_set_msvc_demangler() in gdb_bfd_init(), guarded by HAVE_MSVC_DEMANGLER. Update cp-support.c to handle MSVC-mangled names in GDB's symbol processing. Link GDB against libdemangle-msvc when enabled.
1 parent 5f055c1 commit 8618a7b

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

gdb/Makefile.in

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ INCLUDE_CFLAGS = -I$(INCLUDE_DIR)
160160
# Where is the "-liberty" library? Typically in ../libiberty.
161161
LIBIBERTY = ../libiberty/libiberty.a
162162

163+
# Where is the libdemangle-msvc library? Typically in ../libdemangle-msvc.
164+
LIBDEMANGLE_MSVC = ../libdemangle-msvc/libdemangle-msvc.a
165+
163166
# Where is the CTF library? Typically in ../libctf.
164167
LIBCTF = @LIBCTF@
165168
CTF_DEPS = @CTF_DEPS@
@@ -677,10 +680,11 @@ CLIBS = $(SIM) $(READLINE) $(OPCODES) $(LIBCTF) $(BFD) $(ZLIB) $(ZSTD_LIBS) \
677680
$(LIBEXPAT) $(LIBLZMA) $(LIBIPT) \
678681
$(WIN32LIBS) $(LIBGNU) $(LIBGNU_EXTRA_LIBS) $(LIBICONV) \
679682
$(GMPLIBS) $(SRCHIGH_LIBS) $(LIBXXHASH) $(PTHREAD_LIBS) \
680-
$(DEBUGINFOD_LIBS)
683+
$(DEBUGINFOD_LIBS) $(LIBDEMANGLE_MSVC)
684+
681685
CDEPS = $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) $(CTF_DEPS) \
682686
$(OPCODES) $(INTL_DEPS) $(LIBIBERTY) $(CONFIG_DEPS) $(LIBGNU) \
683-
$(LIBSUPPORT)
687+
$(LIBSUPPORT) $(LIBDEMANGLE_MSVC)
684688

685689
DIST = gdb
686690

gdb/cp-support.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,12 @@ cp_class_name_from_physname (const char *physname)
730730
std::unique_ptr<demangle_parse_info> info;
731731
int done;
732732

733+
#ifdef HAVE_MSVC_DEMANGLER
734+
char *msvc_result = msvc_class_name_from_physname (physname);
735+
if (msvc_result != NULL)
736+
return msvc_result;
737+
#endif
738+
733739
info = mangled_name_to_comp (physname, DMGL_ANSI,
734740
&storage, &demangled_name);
735741
if (info == NULL)
@@ -876,6 +882,12 @@ method_name_from_physname (const char *physname)
876882
struct demangle_component *ret_comp;
877883
std::unique_ptr<demangle_parse_info> info;
878884

885+
#ifdef HAVE_MSVC_DEMANGLER
886+
char *msvc_result = msvc_method_name_from_physname (physname);
887+
if (msvc_result != NULL)
888+
return msvc_result;
889+
#endif
890+
879891
info = mangled_name_to_comp (physname, DMGL_ANSI,
880892
&storage, &demangled_name);
881893
if (info == NULL)
@@ -1652,7 +1664,7 @@ gdb_demangle (const char *name, int options)
16521664
#endif
16531665

16541666
if (crash_signal == 0)
1655-
result.reset (bfd_demangle (NULL, name, options | DMGL_VERBOSE));
1667+
result.reset (bfd_demangle (nullptr, name, options | DMGL_VERBOSE));
16561668

16571669
#ifdef HAVE_WORKING_FORK
16581670
if (catch_demangler_crashes)

gdb/gdb_bfd.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include "gdbsupport/cxx-thread.h"
3737
#include "gdbsupport/unordered_map.h"
3838
#include "gdbsupport/unordered_set.h"
39+
#ifdef HAVE_MSVC_DEMANGLER
40+
#include "demangle.h"
41+
#endif
3942

4043
/* Lock held when doing BFD operations. A recursive mutex is used
4144
because we use this mutex internally and also for BFD, just to make
@@ -1298,7 +1301,12 @@ gdb_bfd_init ()
12981301
if (bfd_init () == BFD_INIT_MAGIC)
12991302
{
13001303
if (bfd_thread_init (gdb_bfd_lock, gdb_bfd_unlock, nullptr))
1301-
return;
1304+
{
1305+
#ifdef HAVE_MSVC_DEMANGLER
1306+
bfd_set_msvc_demangler (msvc_demangle);
1307+
#endif
1308+
return;
1309+
}
13021310
}
13031311

13041312
error (_("fatal error: libbfd ABI mismatch"));

0 commit comments

Comments
 (0)