Repository navigation
[#514] Print line numbers in pgmoneta_backtrace - #521
Conversation
|
@silver-ymz It looks like libbacktrace isn't available in any repositories Can you borrow ideas ? |
| pgmoneta_backtrace(void); | ||
|
|
||
| #endif | ||
| #ifdef DEBUG |
| return 0; | ||
| } | ||
|
|
||
| #ifdef DEBUG |
It seems that only debian and arch have packaged it. I will update the CI and documentation soon. |
|
@silver-ymz You have to make sure that your solution works with RockyLinux |
33ddfea to
e47824a
Compare
e47824a to
540166e
Compare
|
@jesperpedersen Could you help to review it if you have time? Thanks. |
|
You either have to find a solution without Did you try an alternative with |
|
I find 2 alternative solutions.
Do you think the second one is better? |
|
Yes, but for 1) how are you going to build a .RPM for that ? So, you would need to create a subdirectory with the basic necessary files under its license, and then use its API. I guess the key takeaway is that you can't compile external repositories. For 2) it is a question of we can get the information that we need. So, for now you will have to work on both solutions so we can compare. |
|
|
No, you have to do |
|
@silver-ymz Are you ok on this ? |
fe48463 to
5c6006b
Compare
|
Now it uses Example Output: Sorry for not replying for a long time. I've been a bit busy lately. |
| static bool | ||
| calculate_offset(uint64_t addr, uint64_t* offset, char** filepath) | ||
| { | ||
| FILE* fp = fopen("/proc/self/maps", "r"); |
| if (fp == NULL) | ||
| { | ||
| pgmoneta_log_error("Failed to open /proc/self/maps: %s", strerror(errno)); | ||
| return 1; |
| return 1; | ||
| } | ||
|
|
||
| char line[256]; |
There was a problem hiding this comment.
Variables in the beginning of a function
| char* start = strtok(line, "-"); | ||
| char* end = strtok(NULL, " "); | ||
| strtok(NULL, " "); // skip the next token | ||
| char* base_offset = strtok(NULL, " "); |
There was a problem hiding this comment.
Variables in the beginning
| { | ||
| fclose(fp); | ||
| uint64_t base_offset_value = strtoul(base_offset, NULL, 16); | ||
| *offset = addr - start_addr + base_offset_value; |
There was a problem hiding this comment.
You can use pgmoneta_append
| } | ||
| } | ||
| } | ||
| fclose(fp); |
| *offset = addr - start_addr + base_offset_value; | ||
| *filepath = malloc(strlen(filepath_ptr) + 1); | ||
| memcpy(*filepath, filepath_ptr, strlen(filepath_ptr) + 1); | ||
| return 0; |
| uint64_t end_addr = strtoul(end, NULL, 16); | ||
| if (addr >= start_addr && addr < end_addr) | ||
| { | ||
| fclose(fp); |
| continue; | ||
| } | ||
|
|
||
| char cmd[256]; |
There was a problem hiding this comment.
The same comments here...
|
Do |
|
It is ok to only support Linux for now |
5c6006b to
6724a0e
Compare
|
All suggestions have been adopted. Could you review again? |
| #include <message.h> | ||
| #include <workers.h> | ||
|
|
||
| #include <stdlib.h> |
There was a problem hiding this comment.
clangd hints me it's an unused header.
| } | ||
|
|
||
| #ifdef DEBUG | ||
| #ifdef HAVE_LINUX |
There was a problem hiding this comment.
Need to be inside the functions
| end_addr = strtoul(end, NULL, 16); | ||
| if (addr >= start_addr && addr < end_addr) | ||
| { | ||
| goto success; |
There was a problem hiding this comment.
Do a bool success instead, and put it in the while
| } | ||
| } | ||
| } | ||
| goto error; |
There was a problem hiding this comment.
No,
if (!success)
{
goto error;
}
| } | ||
| goto error; | ||
|
|
||
| success: |
| { | ||
| printf("%s\n", strings[i]); | ||
| pgmoneta_log_error("Failed to get backtrace: %s", strerror(errno)); | ||
| return 1; |
| } | ||
|
|
||
| snprintf(cmd, sizeof(cmd), "addr2line -e %s -fC 0x%lx", filepath, offset); | ||
| free(filepath); |
| { | ||
| found_main = true; | ||
| } | ||
| printf("#%d 0x%lx in %s\n", i - 1, addr, buffer); |
There was a problem hiding this comment.
Build up a string using pgmoneta_append and then pgmoneta_log_debug it
| buffer[strlen(buffer) - 1] = '\0'; // Remove trailing newline | ||
| printf("\tat %s\n", buffer); | ||
| } | ||
|
|
| return 0; | ||
| } | ||
|
|
||
| #endif |
There was a problem hiding this comment.
Non-Linux should return 1
6724a0e to
28da67d
Compare
|
Updated now. Could you review again? |
| break; | ||
| } | ||
| } | ||
|
|
| { | ||
| found_main = true; | ||
| } | ||
| log_str_len = snprintf(log_str, sizeof(log_str), "#%d 0x%lx in %s\n", i - 1, addr, buffer); |
There was a problem hiding this comment.
Use pgmoneta_append(s) - you can do
DEBUG: Backtrace
...
...
...
so basically
pgmoneta_append(log_str, "Backtrace:\n") to begin with
| } | ||
|
|
||
| pgmoneta_log_debug("%s", log_str); | ||
|
|
There was a problem hiding this comment.
free(log_str);
Use clang/Debug so you get feedback from ASAN
28da67d to
1f0cdd8
Compare
|
Updated now. Could you review again? |
Use |
Signed-off-by: Mingzhuo Yin <[email protected]>
1f0cdd8 to
de9ef92
Compare
|
Updated now. Could you review again? |
|
Merged. Thanks for your contribution ! |
|
@silver-ymz Please, port this patch to pgagroal and pgexporter |
implement #514
This PR introduces an enhanced stack backtrace feature that provides detailed debugging information, including function names, filenames, and line numbers. When
pgmoneta_backtraceis called, it generates a formatted stack trace that is particularly useful for debugging and troubleshooting.Example Output
The following example demonstrates the output when
pgmoneta_backtraceis invoked from theversionfunction insrc/main.c:206:Details
libbacktraceto capture stack trace information.