diff options
| author | Victor Stinner <vstinner@redhat.com> | 2018-11-13 16:13:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-13 16:13:17 +0100 |
| commit | ae8878176d6dc1878d1e792ac4308ca1920b103b (patch) | |
| tree | 5fc0f2bd9731d652a5ab136d120f4966499a0ffe | |
| parent | 60a6baef4005a32fb4cf45e15942ea18e59ecf19 (diff) | |
| download | cpython-git-ae8878176d6dc1878d1e792ac4308ca1920b103b.tar.gz | |
bpo-29564:_PyMem_DumpTraceback() suggests enabling tracemalloc (GH-10510) (GH-10518)
If tracemalloc is not tracing Python memory allocations,
_PyMem_DumpTraceback() now suggests to enable tracemalloc
to get the traceback where the memory block has been allocated.
| -rw-r--r-- | Lib/test/test_capi.py | 4 | ||||
| -rw-r--r-- | Modules/_tracemalloc.c | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index ae9e08a09b..947da8c562 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -534,6 +534,8 @@ class PyMemDebugTests(unittest.TestCase): r" The block was made by call #[0-9]+ to debug malloc/realloc.\n" r" Data at p: cb cb cb .*\n" r"\n" + r"Enable tracemalloc to get the memory block allocation traceback\n" + r"\n" r"Fatal Python error: bad trailing pad byte") regex = regex.format(ptr=self.PTR_REGEX) regex = re.compile(regex, flags=re.DOTALL) @@ -548,6 +550,8 @@ class PyMemDebugTests(unittest.TestCase): r" The block was made by call #[0-9]+ to debug malloc/realloc.\n" r" Data at p: cb cb cb .*\n" r"\n" + r"Enable tracemalloc to get the memory block allocation traceback\n" + r"\n" r"Fatal Python error: bad ID: Allocated using API 'm', verified using API 'r'\n") regex = regex.format(ptr=self.PTR_REGEX) self.assertRegex(out, regex) diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 4f3bb5463f..a61bdb62fb 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -1492,6 +1492,12 @@ _PyMem_DumpTraceback(int fd, const void *ptr) traceback_t *traceback; int i; + if (!tracemalloc_config.tracing) { + PUTS(fd, "Enable tracemalloc to get the memory block " + "allocation traceback\n\n"); + return; + } + traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr); if (traceback == NULL) return; |
