Skip to content

Commit

Permalink
Support multi heap managers (#45)
Browse files Browse the repository at this point in the history
* add init function in each heap manager

* add ptmalloc glibc version detection

* fix ptmalloc glibc 2.27 + gdb9.2 on Ubuntu 18.04

* move get_glibc_version to heap_ptmalloc files

* rename gHeapInitFuncs to gHeapRegistrationFuncs

* heap.cpp: add macro to check CA_HEAP and enhance its error message

Co-authored-by: Michael Yan <myan@microstrategy.com>
Former-commit-id: ed32610
  • Loading branch information
yanqi27 and Michael Yan authored May 29, 2022
1 parent 6c3b737 commit 95cff1f
Show file tree
Hide file tree
Showing 28 changed files with 4,757 additions and 183 deletions.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
# [Optional] Uncomment this section to install additional packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt install -y texinfo \
&& apt install -y libgmp-dev \
&& apt install -y build-essential \
&& apt install -y wget \
&& apt install -y python-dev \
Expand Down
2 changes: 2 additions & 0 deletions gdbplus/gdb-12.1/gdb/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ COMMON_SFILES = \
go-typeprint.c \
go-valprint.c \
heap.c \
heap_ptmalloc_2_27.c \
heap_ptmalloc_2_31.c \
heap_ptmalloc_2_35.c \
heapcmd.c \
i386-decode.c \
Expand Down
37 changes: 32 additions & 5 deletions gdbplus/gdb-12.1/gdb/gdb_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ inferior_memory_read (address_t addr, void* buffer, size_t sz)
return false;
}

void ca_switch_to_thread(struct thread_info *info)
{
switch_to_thread (info);
}

int ca_num_fields(struct type *type)
{
return type->num_fields();
}

const char *ca_field_name(struct type *type, int i)
{
return type->field(i).name();
}

bool get_gv_value(const char *varname, char *buf, size_t bufsz)
{
struct symbol *sym;

sym = lookup_static_symbol(varname, VAR_DOMAIN).symbol;
if (sym) {
struct value *val = value_of_variable(sym, 0);
if (bufsz >= TYPE_LENGTH(value_type(val))) {
gdb::array_view<const gdb_byte> content = value_contents(val);
memcpy(buf, content.data(), TYPE_LENGTH(value_type(val)));
return true;
}
}
return false;
}

static int
thread_callback (struct thread_info *info, void *data)
{
Expand Down Expand Up @@ -379,8 +410,6 @@ build_segments(void)
bool
update_memory_segments_and_heaps(void)
{
bool rc = true;

/* reset internal quit flag */
g_quit = false;

Expand Down Expand Up @@ -422,9 +451,7 @@ update_memory_segments_and_heaps(void)
return false;
}
/* Probe for heap segments */
CA_HEAP->init_heap();

return rc;
return init_heap_managers();
}

int
Expand Down
1 change: 0 additions & 1 deletion gdbplus/gdb-12.1/gdb/heap_ptmalloc.c

This file was deleted.

1 change: 1 addition & 0 deletions gdbplus/gdb-12.1/gdb/heap_ptmalloc_2_27.c
1 change: 1 addition & 0 deletions gdbplus/gdb-12.1/gdb/heap_ptmalloc_2_31.c
5 changes: 4 additions & 1 deletion gdbplus/gdb-12.1/gdb/heapcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ display_help_command (const char *arg, int from_tty)
static void
switch_heap_command(const char *arg, int from_tty)
{
/* Ensure heap manager is initialized */
if (!update_memory_segments_and_heaps())
return;

if (!arg) {
auto supported_heaps = get_supported_heaps();
CA_PRINT("Please provide the heap manager name, currently supported heap managers: %s.\n", supported_heaps.c_str());
Expand Down Expand Up @@ -292,7 +296,6 @@ void _initialize_heapcmd ();
void
_initialize_heapcmd ()
{
register_heap_managers(); // todo: find a better place to register heaps. maybe update_memory_segments_and_heaps is better than here.
add_cmd("ref", class_info, ref_command, _("Search for references to a given object.\nref <addr_exp>\nref [/thread or /t] <addr_exp> <size> [level]"), &cmdlist);
add_cmd("obj", class_info, obj_command, _("Search for object and reference to object of the same type as the input expression\nobj <type|variable>"), &cmdlist);
add_cmd("shrobj", class_info, shrobj_command, _("Find objects that currently referenced from multiple threads\nshrobj [tid0] [tid1] [...]"), &cmdlist);
Expand Down
4 changes: 3 additions & 1 deletion gdbplus/gdb-9.2/gdb/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,9 @@ COMMON_SFILES = \
go-typeprint.c \
go-valprint.c \
heap.c \
heap_ptmalloc.c \
heap_ptmalloc_2_27.c \
heap_ptmalloc_2_31.c \
heap_ptmalloc_2_35.c \
heap_tcmalloc.c \
heapcmd.c \
i386-decode.c \
Expand Down
37 changes: 32 additions & 5 deletions gdbplus/gdb-9.2/gdb/gdb_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ inferior_memory_read (address_t addr, void* buffer, size_t sz)
return false;
}

void ca_switch_to_thread(struct thread_info *info)
{
switch_to_thread (info->ptid);
}

int ca_num_fields(struct type *type)
{
return TYPE_NFIELDS (type);
}

const char *ca_field_name(struct type *type, int i)
{
return TYPE_FIELD_NAME (type, i);
}

bool get_gv_value(const char *varname, char *buf, size_t bufsz)
{
struct symbol *sym;

sym = lookup_static_symbol(varname, VAR_DOMAIN).symbol;
if (sym) {
struct value *val = value_of_variable(sym, 0);
if (bufsz >= TYPE_LENGTH(value_type(val))) {
const gdb_byte *content = value_contents(val);
memcpy(buf, content, TYPE_LENGTH(value_type(val)));
return true;
}
}
return false;
}

static int
thread_callback (struct thread_info *info, void *data)
{
Expand Down Expand Up @@ -382,8 +413,6 @@ build_segments(void)
bool
update_memory_segments_and_heaps(void)
{
bool rc = true;

/* reset internal quit flag */
g_quit = false;

Expand Down Expand Up @@ -425,9 +454,7 @@ update_memory_segments_and_heaps(void)
return false;
}
/* Probe for heap segments */
CA_HEAP->init_heap();

return rc;
return init_heap_managers();
}

int
Expand Down
1 change: 0 additions & 1 deletion gdbplus/gdb-9.2/gdb/heap_ptmalloc.c

This file was deleted.

1 change: 1 addition & 0 deletions gdbplus/gdb-9.2/gdb/heap_ptmalloc_2_27.c
1 change: 1 addition & 0 deletions gdbplus/gdb-9.2/gdb/heap_ptmalloc_2_31.c
1 change: 1 addition & 0 deletions gdbplus/gdb-9.2/gdb/heap_ptmalloc_2_35.c
1 change: 0 additions & 1 deletion gdbplus/gdb-9.2/gdb/heapcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ switch_heap_command(const char *arg, int from_tty)
void
_initialize_heapcmd (void)
{
register_heap_managers(); // todo: find a better place to register heaps. maybe update_memory_segments_and_heaps is better than here.
add_cmd("ref", class_info, ref_command, _("Search for references to a given object.\nref <addr_exp>\nref [/thread or /t] <addr_exp> <size> [level]"), &cmdlist);
add_cmd("obj", class_info, obj_command, _("Search for object and reference to object of the same type as the input expression\nobj <type|variable>"), &cmdlist);
add_cmd("shrobj", class_info, shrobj_command, _("Find objects that currently referenced from multiple threads\nshrobj [tid0] [tid1] [...]"), &cmdlist);
Expand Down
Loading

0 comments on commit 95cff1f

Please sign in to comment.