Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#7046 Add Linux support to dr_create_memory_dump. #7047

Merged
merged 26 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
162c902
Add Linux support to dr_create_memory_dump.
ivankyluk Oct 18, 2024
37f8abf
Merge branch 'master' into i7046-add-linux-support-to-dr_create_memor…
ivankyluk Oct 18, 2024
7a9b225
Merge branch 'master' into i7046-add-linux-support-to-dr_create_memor…
ivankyluk Oct 30, 2024
13f26ab
Incorporate review comments.
ivankyluk Oct 30, 2024
728ad87
Remove debug code in tracer.cpp.
ivankyluk Oct 30, 2024
b741aeb
Merge branch 'master' into i7046-add-linux-support-to-dr_create_memor…
ivankyluk Oct 31, 2024
838c276
Incorporate review comments. Use dr_suspend_all_other_threads_ex() in…
ivankyluk Nov 1, 2024
ed8e3da
Change FIXME in elf_defines.h to XXX.
ivankyluk Nov 1, 2024
badc146
Merge branch 'master' into i7046-add-linux-support-to-dr_create_memor…
ivankyluk Nov 4, 2024
78d97af
Add unit test to cover dr_create_memory_dump for X64 Linux.
ivankyluk Nov 5, 2024
26edb92
Remove strhash_table_t which triggers lock rack errors in debug build…
ivankyluk Nov 5, 2024
db46f71
Update release note.
ivankyluk Nov 5, 2024
2d5211e
Merge branch 'master' into i7046-add-linux-support-to-dr_create_memor…
ivankyluk Nov 5, 2024
fdaf544
Adding more details to error message.
ivankyluk Nov 6, 2024
d8a5173
Skip vsyscall region.
ivankyluk Nov 6, 2024
9d5a96c
Add a TODO to check the content of the memory dump file.
ivankyluk Nov 6, 2024
0e674a0
Use nudge event for memory dump test. Enable Windows memory dump test.
ivankyluk Nov 6, 2024
5444f30
Enable client.memory_dump_test for WIN32.
ivankyluk Nov 6, 2024
f014ac0
Add Windows specific code to memory_dump_test.dll.c.
ivankyluk Nov 6, 2024
4543ca4
Rewrite the memory dump test for win32.
ivankyluk Nov 6, 2024
5ad051a
Limit the memory dump test to X64 only.
ivankyluk Nov 6, 2024
f41c4aa
Merge branch 'master' into i7046-add-linux-support-to-dr_create_memor…
ivankyluk Nov 7, 2024
73fa0fd
Use a hashtable instead of strstr() to look up existing section names.
ivankyluk Nov 7, 2024
5b5a3fd
Fix the format.
ivankyluk Nov 7, 2024
780df5f
Merge branch 'master' into i7046-add-linux-support-to-dr_create_memor…
ivankyluk Nov 7, 2024
0e9584b
Incorporate review comments.
ivankyluk Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions api/docs/release.dox
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,8 @@ clients.

The changes between version \DR_VERSION and 11.0.0 include the following compatibility
changes:
- Added X64 Linux support to dr_create_memory_dump().

Further non-compatibility-affecting changes include:

**************************************************
<hr>

The changes between version 11.0.0 and 10.0.0 include the following compatibility
changes:
- No compatibility changes.
- Added X64 Linux support to dr_create_memory_dump(). This API has the same
restriction as dr_suspend_all_other_threads_ex().

Further non-compatibility-affecting changes include:
- No changes yet.
Expand Down
46 changes: 26 additions & 20 deletions core/unix/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
#include <sys/mman.h>
#include "../globals.h"

#include <stdio.h>

#include "../hashtable.h"
#include "../os_shared.h"
#include "../synch.h"
#include "dr_tools.h"
#include "elf_defines.h"
#include "memquery.h"
Expand All @@ -42,6 +40,7 @@
#define MAX_SECTION_NAME_BUFFER_SIZE 8192
#define SECTION_HEADER_TABLE ".shstrtab"
#define VVAR_SECTION "[vvar]"
#define VSYSCALL_SECTION "[vsyscall]"

typedef struct _section_header_info_t {
app_pc vm_start;
Expand Down Expand Up @@ -158,14 +157,11 @@ write_section_header(DR_PARAM_IN file_t elf_file,
static bool
os_dump_core_internal(void)
{
strhash_table_t *string_htable =
strhash_hash_create(GLOBAL_DCONTEXT, /*bits=*/8, /*load_factor_percent=*/80,
/*table_flags=*/0, NULL _IF_DEBUG("mmap-string-table"));

// Insert a null string at the beginning for sections with no comment.
char string_table[MAX_SECTION_NAME_BUFFER_SIZE];
// Reserve the first byte for sections without a name.
string_table[0] = '\0';
string_table[1] = '\0';
ELF_ADDR string_table_offset = 1;
ELF_OFF section_count = 0;
ELF_OFF section_data_size = 0;
Expand All @@ -186,16 +182,17 @@ os_dump_core_internal(void)
// the section name in the section name table.
while (memquery_iterator_next(&iter)) {
// Skip non-readable section.
if (iter.prot == MEMPROT_NONE || strcmp(iter.comment, VVAR_SECTION) == 0) {
if (iter.prot == MEMPROT_NONE || strcmp(iter.comment, VVAR_SECTION) == 0 ||
strcmp(iter.comment, VSYSCALL_SECTION) == 0) {
continue;
}
ELF_ADDR offset = 0;
if (iter.comment != NULL && iter.comment[0] != '\0') {
offset = (ELF_ADDR)strhash_hash_lookup(GLOBAL_DCONTEXT, string_htable,
iter.comment);
const char *pos = strstr(&string_table[1], iter.comment);
ivankyluk marked this conversation as resolved.
Show resolved Hide resolved
if (pos != NULL) {
offset = pos - string_table;
}
if (offset == 0) {
strhash_hash_add(GLOBAL_DCONTEXT, string_htable, iter.comment,
(void *)string_table_offset);
const size_t comment_len = d_r_strlen(iter.comment);
if (comment_len + string_table_offset > MAX_SECTION_NAME_BUFFER_SIZE) {
SYSLOG_INTERNAL_ERROR("Section name table is too small to store "
Expand Down Expand Up @@ -269,6 +266,10 @@ os_dump_core_internal(void)
if (written != length) {
SYSLOG_INTERNAL_ERROR("Failed to write the requested memory content into "
"the core dump file.");
SYSLOG_INTERNAL_ERROR(
"section: %s, prot: %x, length: %d, written: %d\n",
&string_table[section_header_info[section_index].name_offset],
section_header_info[section_index].prot, length, written);
os_close(elf_file);
return false;
}
Expand Down Expand Up @@ -319,7 +320,6 @@ os_dump_core_internal(void)
}

os_close(elf_file);
strhash_hash_destroy(GLOBAL_DCONTEXT, string_htable);
return true;
}

Expand All @@ -329,17 +329,23 @@ os_dump_core_internal(void)
bool
os_dump_core_live(void)
{
uint num_threads;
void **drcontexts = NULL;
// Suspend all threads including native threads to ensure the memory regions
// do not change in the middle of the core dump.
if (!dr_suspend_all_other_threads_ex(&drcontexts, &num_threads, NULL,
DR_SUSPEND_NATIVE)) {
int num_threads;
thread_record_t **threads;
if (!synch_with_all_threads(THREAD_SYNCH_SUSPENDED_VALID_MCONTEXT_OR_NO_XFER,
&threads, &num_threads, THREAD_SYNCH_NO_LOCKS_NO_XFER,
/* If we fail to suspend a thread, there is a
* risk of deadlock in the child, so it's worth
* retrying on failure.
*/
THREAD_SYNCH_SUSPEND_FAILURE_IGNORE)) {
return false;
}

const bool ret = os_dump_core_internal();
if (!dr_resume_all_other_threads(drcontexts, num_threads)) {
return false;
}

end_synch_with_all_threads(threads, num_threads,
/*resume=*/true);
return ret;
}
ivankyluk marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2646,6 +2646,10 @@ if (NOT ANDROID) # TODO i#38: Port test to Android.
torunonly_ci(client.attach_blocking linux.infloop client.attach_test.dll
client-interface/attach_blocking.runall "" "" "")
endif ()
if (LINUX AND X64)
ivankyluk marked this conversation as resolved.
Show resolved Hide resolved
# TODO i#7046: Verify the content of the output file.
ivankyluk marked this conversation as resolved.
Show resolved Hide resolved
tobuild_ci(client.memory_dump_test client-interface/memory_dump_test.c "" "" "")
endif ()
endif ()

if (UNIX)
Expand Down
1 change: 0 additions & 1 deletion suite/tests/client-interface/memory_dump_test.dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ DR_EXPORT
void
dr_init(client_id_t id)
{
void *drcontext = dr_get_current_drcontext();
dr_register_exit_event(dr_exit);
dr_register_thread_init_event(dr_thread_init);
dr_fprintf(STDERR, "thank you for testing memory dump\n");
Expand Down
1 change: 0 additions & 1 deletion suite/tests/client-interface/memroy_dump_test.runall

This file was deleted.

Loading