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

Exception when debugged process is compiled without "-g" #3

Closed
sriemer opened this issue Jul 7, 2014 · 4 comments
Closed

Exception when debugged process is compiled without "-g" #3

sriemer opened this issue Jul 7, 2014 · 4 comments

Comments

@sriemer
Copy link

sriemer commented Jul 7, 2014

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;
}
@teawater
Copy link
Owner

Hi,

I am sorry for deal with this issue later because I just caught cold in last 2 days.
The cause of this issue is I forgot remove a temp "raise Exception".
I just committed a new commit that can handle this issue in my part. Could you help me do a test?

Thanks,
Hui

@teawater teawater reopened this Jul 10, 2014
@sriemer
Copy link
Author

sriemer commented Jul 10, 2014

I've tested it with this basic tool without -g, also stripped and also with PIE. It works but it seems to be quite slow backtracing all mallocs. I'll test with Linux games later on.
With my own game cheating tool ugtrain I first record all mallocs, use scanmem to find an unique malloc and this way I get the object size. In the second step I filter with it and need to backtrace only few mallocs.

@teawater
Copy link
Owner

I have the plan for add filter and put more clear data in CSV file.
I think the cause of speed issue is when GDB do backtrace with a program that doesn't have enough debug info, it need parse the asm code to get its behavior.

PS, the current issue is fixed, right? Do you mind close it and open some new issues for the current troubles.

@sriemer
Copy link
Author

sriemer commented Jul 15, 2014

Yes, let's close this as it works on Ubuntu 12.04 precise at least. There are a lot more issues. E.g. Ubuntu 14.04 trusty complains about syntax errors.

I also still don't get the advantage over using a C library hooking memory allocations. This is not stopping the CPU all the time and can work with parallel threads. Works so good that I saw interleaving and have to use flockfile(); fputs_unlocked(); funlockfile(); to write the memory information out with stream caching but without interleaving. Realtime stuff like OpenGL will just end the process if it detects that it's running too slow. Even just using GNU backtrace() at a depth of 3 to just get code addresses on the stack on all allocations is too slow.

@sriemer sriemer closed this as completed Jul 15, 2014
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

2 participants