简体   繁体   中英

Set breakpoint at function inside dll in Visual Studio?

I want to set a breakpoint at a specific function that's located in a dll. The pdb's are public so I know the function name (say namespace1::namespace2::className::functionName ), but no sources.

Is there a way to do this in Visual Studio?

I've tried "Breakpoints -> New -> Break at function". I wouldn't be asking had that worked. :)

void wrapper_func(parameters...){
    // call the real function
    std::cout<<"before call dll func"<<std::endl;
    namespace1::namespace2::className::functionName(parameters...);
    std::cout<<"after call dll func"<<std::endl;
}

then set breakpoint on wrapper_func.but you need to do some work to call the wrapper func instead of the dll func.

another way is set breakpoint on function address

If you don't like to load the NT symbols, there is another method Get the relative address of the function in which you want to set breakpoint with some PE tools. For example, just type “dumpbin /exports C:\\Windows\\System32\\user32.dll” in the Visual Studio command line, you can get “RVA” of each exported symbol in “user32.dll”. For instance, “RVA” of “GetMessageW” is “000091C6”.

Now check the image base of “user32.dll” in the VS debugger's “Modules” windows, the values is “7E410000” on my laptop (Generally, the system dlls would not be relocated, so the image base value here is equal to the value written in PE file). Then the starting address of “GetMessageW” is “7E410000+000091C6= 7E4191C6”. Just set a function breakpoint at this address. Then the debugger will stop when calling into “GetMessageW”

see this bolg

You will need the Source Code Files which contains the function which you want to debug. pdb files has information/directions to get you to function. https://en.wikipedia.org/wiki/Program_database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM