teawater / cma Goto Github PK
View Code? Open in Web Editor NEWC/C++ Dynamic Memory Analyzer (CMA)
Home Page: http://teawater.github.io/cma/
C/C++ Dynamic Memory Analyzer (CMA)
Home Page: http://teawater.github.io/cma/
tried 3 times, only got a traceback one time while press ctrl ^ C, the others got csv files successfully. The traceback should not be a big as we are debugging and we can try again. I think you can mark this issue as fixed. Thank you for your hard work!
The traceback attached below whatever:
Breakpoint 5, 0xb7e50260 in free () from /lib/i386-linux-gnu/libc.so.6
Continuing.
Breakpoint 5, 0xb7e50260 in free () from /lib/i386-linux-gnu/libc.so.6
^CTraceback (most recent call last):
File "/root/cma.py", line 549, in
breaks[r.group(1)].event()
File "/root/cma.py", line 373, in event
gdb.execute("finish", False, True)
KeyboardInterrupt: Quit
(gdb) bt
#0 0xb7e50260 in free () from /lib/i386-linux-gnu/libc.so.6
#1 0xb7e18c3d in vfprintf () from /lib/i386-linux-gnu/libc.so.6
#2 0xb7e4026b in vsnprintf () from /lib/i386-linux-gnu/libc.so.6
#3 0xb7e22f43 in snprintf () from /lib/i386-linux-gnu/libc.so.6
#4 0x08064d97 in zmalloc_get_rss () at zmalloc.c:369
#5 0x0805d494 in serverCron (eventLoop=0x60037350, id=0, clientData=0x0) at redis.c:1029
#6 0x0805915e in processTimeEvents (eventLoop=0x60037350) at ae.c:311
#7 0x08059444 in aeProcessEvents (eventLoop=0x60037350, flags=3) at ae.c:423
#8 0x0805954f in aeMain (eventLoop=0x60037350) at ae.c:455
#9 0x08063314 in main (argc=1, argv=0xbffff2d4) at redis.c:3178
Leon
the following error can be reproduced everytime. Tried target: redis-server, redis-cli. ran on Linux ubuntu 3.3.8, 32bit vmware. ubuntu-12.04.3-desktop-i386, rebuild kernel to 3.3.8, x86
root@ubuntu:~/db/src# gdb redis-server
GNU gdb (GDB) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from redis-server...done.
(gdb) source /root/gdb-7.7.1/cma.py
Please Input the config file:[/root/db/src/cma.conf]
Language is set to Chinese.
记录文件是“/root/db/src/cma.csv”。
脚本将记录已经被释放掉的内存信息。
脚本将记录backtrace信息。
脚本将记录内存函数“malloc/free”。
Breakpoint 3 at 0xb7e51d80 (2 locations)
Breakpoint 4 at 0xb7e52260 (2 locations)
Continuing.
Breakpoint 3, 0xb7e51d80 in malloc () from /lib/i386-linux-gnu/libc.so.6
Continuing.
Breakpoint 3, 0xb7e51d80 in malloc () from /lib/i386-linux-gnu/libc.so.6
Continuing.
Breakpoint 3, 0xb7e51d80 in malloc () from /lib/i386-linux-gnu/libc.so.6
Continuing.
Breakpoint 3, 0xb7e51d80 in malloc () from /lib/i386-linux-gnu/libc.so.6
Traceback (most recent call last):
File "/root/gdb-7.7.1/cma.py", line 364, in
size = arch.get_arg1()
File "/root/gdb-7.7.1/cma.py", line 196, in get_arg1
return long(gdb.parse_and_eval("*(unsigned long *)($ebp+8)"))
gdb.MemoryError: Cannot access memory at address 0x10
(gdb)
gdb
(gdb) target remote :1111
Remote debugging using :1111
warning: Could not load vsyscall page because no executable was specified
try using the "file" command first.
0x00007ffff7ddb2d0 in ?? ()
(gdb) info b
No breakpoints or watchpoints.
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x0000000000400e82 in ?? ()
(gdb) source ~/cma/cma.py
Please Input the config file:[/home/teawater/tmp/cma.conf]
Language is set to Chinese.
记录文件是“/home/teawater/tmp/cma.csv”。
脚本将记录已经被释放掉的内存信息。
脚本将记录backtrace信息。
是否记录内存函数malloc/calloc/realloc/free? [Yes]/No:
是否记录内存函数new/delete? [Yes]/No:
是否记录内存函数kmalloc/kfree? [Yes]/No:
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x0000000000400e82 in ?? ()
[0] 记录内存信息到“/home/teawater/tmp/cma.csv”。
[1] 继续。
[2] 退出并记录内存信息到“/home/teawater/tmp/cma.csv”。
哪个操作?[0]2
内存信息存入“/home/teawater/tmp/cma.csv”。
Wrong code:
#try:
#b = Break_alloc("malloc", "<malloc")
#except BreakException:
#record_malloc = False
#else:
#break_is_available = True
#record_malloc = yes_no(lang.string("Do you want to record memory function malloc/calloc/realloc/free?"), True)
#if record_malloc:
#breaks[b.trigger] = b
#try:
#b = Break_calloc("calloc", "<calloc", memtype="malloc")
#breaks[b.trigger] = b
#except BreakException:
#pass
#try:
#b = Break_realloc("realloc", "<realloc", memtype="malloc")
#breaks[b.trigger] = b
#except BreakException:
#pass
#try:
#b = Break_release("free", "<free", memtype="malloc")
#breaks[b.trigger] = b
#except BreakException:
#pass
#try:
#b = Break_alloc("operator new", r'<operator new\(', '<operator new(', 'new')
#except BreakException:
#record_new = False
#else:
#break_is_available = True
#record_new = yes_no(lang.string("Do you want to record memory function new/delete?"), True)
#if record_new:
#breaks[b.trigger] = b
#try:
#b = Break_release("operator delete", r'<operator delete\(', '<operator delete(', 'new')
#breaks[b.trigger] = b
#except BreakException:
#pass
I've tested the cma tool and it only works with binaries compiled with the "-g" option. Otherwise, an exception is raised. IMHO it shouldn't crash if that information isn't available.
Breakpoint 2, 0x00007ffff7a9cf20 in malloc () from /lib/x86_64-linux-gnu/libc.so.6
Traceback (most recent call last):
File "cma.py", line 558, in
breaks[r.group(1)].event()
File "cma.py", line 360, in event
not_released_add(arch.get_ret(), size, self.memtype)
File "cma.py", line 230, in not_released_add
not_released[addr].append(get_info_line(True))
File "cma.py", line 165, in get_info_line
raise Exception
Exception
My simple malloc and static memory test tool:
/* compile with: gcc -O2 -Wall -o malloctest malloctest.c */ #include <stdlib.h> #include <stdio.h> #include <unistd.h> static int magic_var = 0xdeadbeef; int main (void) { int i = 0; int *j; while(1) { sleep(1); j = malloc(sizeof(int)); *j = i; printf("&magic_var: %p, magic_var: %#x, value: %#x\n", &magic_var, magic_var, magic_var + *j); free(j); i++; if (i > 15) i = 0; } return 0; }
I was hoping to use a modified version of this tool to assist in a new python based gdb ui. To do that I would need this software to have a license permitting such use. My tool will be open source, and I will most certainly give credit where it is due.
What license have you released this tool under?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.