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

does not resolve line-numbers #14

Closed
ghost opened this issue Jun 10, 2020 · 21 comments
Closed

does not resolve line-numbers #14

ghost opened this issue Jun 10, 2020 · 21 comments

Comments

@ghost
Copy link

ghost commented Jun 10, 2020

Hi,

When it finds a problem, it emits:
./constatus(Z15send_index_htmlP13http_thread_tRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_P10instance_tP6sourceS8+0x5f4) [0x555555916ca6]

That is without line-numbers. Can you maybe add that to libleak? Would be a great help :-)

@WuBingzheng
Copy link
Owner

Because the backtrace is showed by backtrace_symbols(2), which does not show the line number.

libleak used to show backtrace by libunwind, which can show line number.
You may checkout that commit: fec6426

@ghost
Copy link
Author

ghost commented Jun 11, 2020

Unfortunately that commit crashes at start.

@WuBingzheng
Copy link
Owner

Maybe you could try addr2line(1) to transfer addresses in libleak's log to line number.

@WuBingzheng
Copy link
Owner

I use libbacktrace to replace backtrace(3).
So there are filename and number now.

@ghost
Copy link
Author

ghost commented Jun 15, 2020

Hi,
Thanks!
Unfortunately it immediately crashes:

==19850== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==19850== Bad permissions for mapped region at address 0x12055000
==19850== at 0x483EA6E: strstr (vg_replace_strmem.c:1643)
==19850== by 0x4847674: lib_maps_build (libleak.c:172)
==19850== by 0x48478DE: init (libleak.c:340)
==19850== by 0x400F369: call_init.part.0 (dl-init.c:72)
==19850== by 0x400F468: call_init (dl-init.c:30)
==19850== by 0x400F468: _dl_init (dl-init.c:119)
==19850== by 0x40010C9: ??? (in /lib/x86_64-linux-gnu/ld-2.30.so)
==19850== by 0x2: ???
==19850== by 0x1FFEFFFED2: ???
==19850== by 0x1FFEFFFEE2: ???
==19850== by 0x1FFEFFFEE5: ???

@WuBingzheng
Copy link
Owner

Do you use LEAK_LIB_BLACKLIST? Would you like paste your command here? such as:

LD_PRELOAD=/home/wub/libleak/libleak.so LEAK_EXPIRE=2 LEAK_LIB_BLACKLIST=libmysqlclient.so LEAK_AFTER=1 ./a.out

Besides, would you like help to debug? Apply the following patch to print some debug info and show me the output.

Thanks
Wu

diff --git a/libleak.c b/libleak.c
index 262c32e..d3e4983 100644
--- a/libleak.c
+++ b/libleak.c
@@ -169,6 +169,8 @@ static void lib_maps_build(void)
                lib->start = start;
                lib->end = end;
                if (conf_lib_blacklist != NULL) {
+                       printf("libleak debug: %s %s\n", conf_lib_blacklist, path);
+                       printf("libname: %s\n", lib->name);
                        lib->enabled = strstr(conf_lib_blacklist, lib->name) == NULL;
                } else {
                        lib->enabled = true;

@ghost
Copy link
Author

ghost commented Jun 15, 2020 via email

@WuBingzheng
Copy link
Owner

more patch here, please try this.
Thanks very much

diff --git a/libleak.c b/libleak.c
index 262c32e..0249d98 100644
--- a/libleak.c
+++ b/libleak.c
@@ -54,8 +54,8 @@ static pid_t (*leak_real_fork)(void); /* open new log file for new process */


 /* ### running flags */
-static bool leak_inited;
-static __thread bool leak_in_process;
+static bool leak_inited = false;
+static __thread bool leak_in_process = false;
 static FILE *leak_log_filp;

@WuBingzheng
Copy link
Owner

What's your OS and distribution?

@ghost
Copy link
Author

ghost commented Jun 15, 2020 via email

@WuBingzheng
Copy link
Owner

I will find a Debian to try it.

Please try a last patch (move the hooks down):

@@ -309,22 +311,6 @@ static void __attribute__((constructor))init(void)
                conf_start_ms = leak_now_ms() + atoi(ev) * 1000;
        }

-       /* hook symbols */
-       leak_real_malloc = dlsym(RTLD_NEXT, "malloc");
-       assert(leak_real_malloc != NULL);
-
-       leak_real_realloc = dlsym(RTLD_NEXT, "realloc");
-       assert(leak_real_realloc != NULL);
-
-       leak_real_calloc = dlsym(RTLD_NEXT, "calloc");
-       assert(leak_real_calloc != NULL);
-
-       leak_real_free = dlsym(RTLD_NEXT, "free");
-       assert(leak_real_free != NULL);
-
-       leak_real_fork = dlsym(RTLD_NEXT, "fork");
-       assert(leak_real_fork != NULL);
-
        /* init dict and memory pool */
        leak_callstack_dict = wuy_dict_new_func(leak_callstack_hash,
                        leak_callstack_equal,
@@ -354,6 +340,22 @@ static void __attribute__((constructor))init(void)
        fprintf(leak_log_filp, "# start detect. expire=%lds\n", conf_expire);
        fflush(leak_log_filp);

+       /* hook symbols */
+       leak_real_malloc = dlsym(RTLD_NEXT, "malloc");
+       assert(leak_real_malloc != NULL);
+
+       leak_real_realloc = dlsym(RTLD_NEXT, "realloc");
+       assert(leak_real_realloc != NULL);
+
+       leak_real_calloc = dlsym(RTLD_NEXT, "calloc");
+       assert(leak_real_calloc != NULL);
+
+       leak_real_free = dlsym(RTLD_NEXT, "free");
+       assert(leak_real_free != NULL);
+
+       leak_real_fork = dlsym(RTLD_NEXT, "fork");
+       assert(leak_real_fork != NULL);
+
        leak_inited = true;
 }

@WuBingzheng
Copy link
Owner

would you like paste you test-program here? Thanks

@ghost
Copy link
Author

ghost commented Jun 15, 2020 via email

@ghost
Copy link
Author

ghost commented Jun 15, 2020 via email

@WuBingzheng
Copy link
Owner

WuBingzheng commented Jun 15, 2020

Maybe you can keep the last patch only (move the hooks down), and remove the first patch (printf debug logs), and try again.
Thanks for help.

@WuBingzheng
Copy link
Owner

Maybe your test-program is too complex. Would you like to try a simple one?

$ cat test1.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
	char *a = malloc(1);
	printf("hello, \n");
	sleep(2);
	char *b = malloc(1);
	printf("world.\n");
	sleep(2);
	free(a);
	sleep(1);
	return 1;
}

$ cc test1.c -g
$ LD_PRELOAD=/home/wub/libleak/libleak.so LEAK_EXPIRE=1  ./a.out
$ cat /tmp/libleak.*

@WuBingzheng
Copy link
Owner

WuBingzheng commented Jun 16, 2020

I think I have known the reason, and fixed it.
Please try the newest commit.

@ghost
Copy link
Author

ghost commented Jun 16, 2020 via email

@WuBingzheng
Copy link
Owner

I install Debian 10.4, build your project constatus, test it with libleak, and it's OK.

wub@debian:~/constatus-master/build$ LD_PRELOAD=/home/wub/libleak/libleak.so ./constatus -c../constatus.cfg
2020-06-17 05:58:24.071737  INFO constatus  With libconfig 1.5.0
2020-06-17 05:58:24.072754  INFO constatus  Loading ../constatus.cfg...
2020-06-17 05:58:24.083192  INFO constatus   *** constatus v4.1 starting ***
2020-06-17 05:58:24.084694  INFO constatus  Generic resizer instantiated
2020-06-17 05:58:24.085459  INFO constatus  Configuring maintenance settings...
2020-06-17 05:58:24.091258  INFO constatus  Configuring default failure handling...
2020-06-17 05:58:24.091920  INFO constatus  Configuring the video-source 1-1...
Source-type "v4l" is not known
2020-06-17 05:58:24.093107 ERROR constatus  Source-type "v4l" is not known
wub@debian:~/constatus-master/build$ ls /tmp/libleak*
/tmp/libleak.9442  /tmp/libleak.9456  /tmp/libleak.9457

It's strange.

Do you mind to try the followings?

  1. I commit new code. Please pull and try it.

  2. Run a simple program with libleak in your environment.

@ghost
Copy link
Author

ghost commented Jun 17, 2020 via email

@WuBingzheng
Copy link
Owner

Thanks very much for it.
I add some comments at your patch. Would you like update it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant