ssbssa / heob

Detects buffer overruns and memory leaks.
Boost Software License 1.0
155 stars 25 forks source link

I want to use heob in cmd.exe to test the app. How should I use it? Can you give me an example? #30

Closed lycfr closed 8 months ago

lycfr commented 8 months ago

I want to use heob in cmd.exe to test the app. How should I use it? Can you give me an example?

ssbssa commented 8 months ago

Depends on what you want to test.

For memory leaks I would suggest: heob64 -vleaks.svg -p0 YourApp.exe And when finished check leaks.svg.

To check for heap buffer overruns and use of already freed memory: heab64 -f1 -l0 YourApp.exe If any problem is detected, you program will crash, and heob will show the reason (if it knows it). But beware that this will slow down your program, and also needs a lot more memory.

lycfr commented 8 months ago

Thank you for your answer, but I still have 2 questions:

  1. If my app has multiple processes running, how should I capture the leak?
  2. If my app is already running, I can still use heob to capture the leak. If so, how should I do it? I have seen the -A parameter, but I am not sure how to use it.
ssbssa commented 8 months ago

If my app has multiple processes running, how should I capture the leak?

How are the multiple processes started? If they are all started from the first instance, then you can let heob automatically attach to child processes, by specifying %p or %c in the output filename, for example: heob64 -vleaks-%c-%n.svg -p0 YourApp.exe

If my app is already running, I can still use heob to capture the leak. If so, how should I do it? I have seen the -A parameter, but I am not sure how to use it.

With heob it's not possible to attach to an already running process. -A works only for processes that where started with CREATE_SUSPENDED, that's what heob itself uses when attaching to child processes.

lycfr commented 8 months ago

Thank you for your patient answer. The multi-process I expressed is similar to the chrome main process where there are many sub-processes. image So, I can only start the app.exe process through heob to test ?

ssbssa commented 8 months ago

So, I can only start the app.exe process through heob to test ?

Yes. If it's not possible to start the main process with heob, it will not work, because the various allocation functions (malloc, free, ...) have to be overridden from the start by heob.

Is there some reason you can't start you application with heob?

lycfr commented 8 months ago

Yeah,I just used the instructions you provided to execute it, heob64 -vleaks-%c-%n.svg -p0 YourApp.exe

and finally found that the .svg file was too large and prevented Chrome from loading it. Is there any way to limit the file size or use other file methods to save it? image

ssbssa commented 8 months ago

It's possible to filter out the smaller leaks with -z, for example -z1000 would only show (combined) leaks that have at least 1000 bytes.

Files this size usually work for me, it may take a few minutes to load, but after that it should work (but I use firefox, which might behave differently).

lycfr commented 8 months ago

Using -z does filter out a lot of information, but now I find it difficult to understand the generated report. Can you provide some ways to read it in the report? After I opened it using chrome, the display was not very good. image leaks-1-XiuXiu I plan to recommend heob to others

ssbssa commented 8 months ago

Not sure if you noticed, but this svg file is an interactive flame graph, so you can zoom into regions of interest if you click on it with the mouse. As for the contents, it looks like all of this is in Qt libraries, and the color suggests there is no debug info available (where debug information is available, it should be pink-ish). A lot of time these Qt leaks are not real 'leaks', though I wonder what the size of that 2 big blocks on the left are, looks like some image related stuff.

What kind of leaks are you looking for, one-time allocations, or is the used memory of your program slowly growing?

lycfr commented 8 months ago

I see that the report is divided into different colors. Can you explain what each color means? Or if I have a leak, where will it be reflected and can be viewed? leaks.zip I uploaded a svg file

ssbssa commented 8 months ago

I see that the report is divided into different colors. Can you explain what each color means?

Blue is just for the different threads. You only have turquoise blocks, which is used if no debug info is available. If you had debug info for your application, it would show in pink.

You really need debug info, at least for your main application, otherwise heob will not be able to give you useful information.

Or if I have a leak, where will it be reflected and can be viewed?

Everything that is shown in the svg could be considered a leak, at least it means that it was not freed by the application.

lycfr commented 8 months ago

Your answer is very helpful to me. What parameters do I need to enable debugging? Do I need source code for debug mode?

ssbssa commented 8 months ago

What parameters do I need to enable debugging?

I'm not sure what you mean by that. You application has to be compiled with debug info enabled.

Do I need source code for debug mode?

heob does not need the source code, but you probably will need it once heob has debug info and tells you the source code location of some leaks.

lycfr commented 8 months ago

👍Thank you for your answer , I understand.

ssbssa commented 8 months ago

I'm closing this now. If you have any more questions, feel free to reopen.