-
Notifications
You must be signed in to change notification settings - Fork 103
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
Debugging a dll being loaded by another application. #91
Comments
Could you please clarify, another managed application create new child process with your dll? |
It doesn't create a child process (not that I know of), it's another dotnet application that loads the dll at runtime and runs code from it. |
You could start debug session for application that loads the dll at runtime and use
|
Is there a way to explicitly pass it certain PDBs? |
No, you can't do this, since this is process-related feature. We can't mark some executable managed code with JMC in runtime and some just ignore, runtime will not understand this correctly and, for example, will be not able to setup stepper in proper way or detect user-unhandled exception.
As I know, vimspector support netcoredbg usage with VSCode protocol, we support JMC feature setup for VSCode protocol too with |
Where should the pdb of the dll I want to debug be? I've put it in the working directory, same directory as the dll I'm actually running and it doesn't seem to be working (I am quite sure I have justMyCode enabled). For context, the dll being loaded by the application is one that's zipped alongside other files, which is then loaded. Everything is in completely different directories from my actual code so I'm not sure where the pdb should go. |
PDB file should be in same directory as DLL. In case CLI you could check output into terminal from debugger during DLL load (this output have info about is DLL loaded with PDB/symbols or not). Note, VSCode protocol also provide information about symbols (PDB) load, but I don't know how and where you could see this log in vimspector. |
Looking at the logs, I believe symbols aren't being loaded properly.
I'll refer to the dll I'm running as the parent dll and the dll being loaded by the parent that I actually want to debug as the child dll just for clarity. It seems no symbols are being found, which is strange since I put the pdb of the child dll both in the working directory of the parent dll and next to the child dll. In the event that you meant that it goes next to the child dll, there's a small issue where the child dll is within a zip file when it's loaded, so I don't think a pdb can be gotten from there. I'm also not sure why there's no path listed or why it's not a .dll, and I'm wondering if the working directory is maybe changing? I doubt the debugger directory should be changing though. Some other dlls (not the parent or child) are in release mode, and I'm getting a message that |
Note, DLL file on disk should be DLL, since debugger will open this file with PE Reader and read CoreView section in order to get PDB file name (DLL have this data stored inside during build). netcoredbg/src/managed/SymbolReader.cs Line 1147 in a8bd3b9
https://docs.microsoft.com/en-us/dotnet/api/system.reflection.portableexecutable.pereader?view=net-6.0 https://docs.microsoft.com/en-us/dotnet/api/system.reflection.portableexecutable.codeviewdebugdirectorydata?view=net-6.0 If you have DLL file archived on disk - this will not work for sure.
No. |
I've come back to this recently, and I've found something that "works". By default, the parent loads my dll and pdb using
Changing to the parent loading assemblies with Is there any reason why netcoredbg cannot use the pdb when loaded using |
As I already explained in #91 (comment) |
How difficult would it be to implement loading the pdb when using |
This require some time for investigation, but for now we don't have it. I have no idea for now how this could be implemented. |
This probably isn't a great idea but a temporary solution could be some config file where you can define where some assembly loaded from stream has a pdb file. |
When assembly loaded from stream it doesn't have file name and many internal logic based on it will not work. For now for debugging you can load dlls from file system and for release build from streams: #if DEBUG
var dll = AssemblyLoadContext.LoadFromAssemblyPath(path);
#else
var dll = AssemblyLoadContext.LoadFromStream(dllStream);
#endif |
Loading both from stream is what's currently happening so that's good.
It's not my project that's loading the dlls, so I'm not able to make that change, sadly. |
General question: if I attach the debugger to the host process, then load a separate DLL through AssemblyLoadContext, put a breakpoint in there, does this halt the complete host app? Or would it be isolated to the assembly context? |
Not sure our debugger work with Context related feature at all, at least we don't have "Context" related stuff implemented (and never tested this case). BTW, I am not sure is this is same "Context" or not, but as I could see Debug API still don't have implemented related interface: |
This change replaces `LoadFromStream` with a direct `LoadFromAssemblyPath` to allow the C# module to interface with `netcoredbg` This solution comes from this issue: Samsung/netcoredbg#91 (comment)
I have a dll, which is loaded by another application at runtime. How would I go about debugging my dll while it's being run from the other application?
The text was updated successfully, but these errors were encountered: