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

Allow the use of debugging symbols in a separate file #96

Merged

Conversation

michailf
Copy link
Contributor

This PR resolves issue #17

It introduces a new option -l (lower case L) to allow specifying a debug link to an external debug information file. If the the option is not specified, the image file is checked for .gnu_debuglink section, and that link is used. The option has precedence over the link in the image file.

The debug information file will be loaded from the same directory as the image file. If the file is not found, it will be loaded from the .debug subdirectory. If the debug link is an absolute path, it will be used as-is.

Copy link
Owner

@rainers rainers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. Looks pretty good, just a few nits.

src/cv2pdb.cpp Outdated
CV2PDB::CV2PDB(PEImage& image, DebugLevel debug_)
: img(image), pdb(0), dbi(0), tpi(0), ipi(0), libraries(0), rsds(0), rsdsLen(0), modules(0), globmod(0)
CV2PDB::CV2PDB(PEImage& image, PEImage* imageDWARF, DebugLevel debug_)
: img(image), imgDWARF(imageDWARF ? imageDWARF : &image), pdb(0), dbi(0), tpi(0), ipi(0), libraries(0), rsds(0), rsdsLen(0), modules(0), globmod(0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a bit confusing that imgDWARF is also used for the CodeView part. I haven't checked how often img is still used now, but couldn't it be initialized with img(imageDWARF ? *imageDWARF : image) instead, and image be kept in some exeImage reference/pointer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imgDWARF will always be NULL for CodeView.

If exe image has either CV entries or DWARF entries, it will be assigned to img and imgDWARF will be NULL. This logic remains as in the original code.

If there is a debug link, either specified by the switch or present in the exe image, code will attempt to load the linked DWARF image. In this case, img will be the exe image and imgDWARF will be the linked DWARF image.

Otherwise a separate .dbg is loaded (CodeView) and assigned to img and imgDWARF will be NULL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CV2PDB initialization, imageDWARF will refer to img if the pointer was NULL.

Perhaps renaming imageDWARF is the correct choice because it can point to img which in turn can be either exe image or CV image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

img is what code modifies while imgDWARF is a "read-only" image. Just trying to come up with a good name for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed imgDWARF member to cimgDebugInfo and made it const

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, img is still used for other purposes. cimgDebugInfo is fine with me, though a bit long. Maybe just imgDI or imgDbg with a commit at the declaration site?

Copy link
Contributor Author

@michailf michailf Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with a commit at the declaration site

Don't understand the lingo. Did you mean "comment"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand the lingo. Did you mean "comment"?

Oops. Indeed that's what I meant ;)

@@ -180,18 +180,18 @@ bool CV2PDB::openPDB(const TCHAR* pdbname, const TCHAR* pdbref)
printf("DBI::QueryImplementationVersion() = %d\n", dbi->QueryImplementationVersion());
#endif

rc = pdb->OpenTpi("", &tpi);
// The default is "r" mode. We need "rw" mode so TPI gets created if it does not exist
rc = pdb->OpenTpi("rw", &tpi);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Is there official documentation for this by now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at their source code to see what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might fix #87

struct _stat buffer;

if (debug_link || exe.hasDebugLink())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this part be extracted to some function?

Copy link
Contributor Author

@michailf michailf Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way? One checks a command line switch and the other checks if the image has a debug link section. Or do you mean the whole block?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I meant the whole block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -359,7 +359,7 @@ Location decodeLocation(const DWARF_Attribute& attr, const Location* frameBase,
}
}

assert(stackDepth > 0);
//assert(stackDepth > 0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these asserts removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hitting this and another assert while testing with a Golang CGO DLL. I do not really know what is the problem being detected by this (and the other one I commented out) asserts.

I can roll these back as I have not touched this code.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to keep the asserts, so it can be investigated if it comes up again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the commit

@michailf michailf force-pushed the feature/use-separate-debugging-symbols branch 3 times, most recently from c7c6ca0 to c5e103f Compare February 19, 2025 16:04
@michailf michailf force-pushed the feature/use-separate-debugging-symbols branch from c5e103f to 82d192b Compare February 19, 2025 16:12
@rainers rainers merged commit 3f676af into rainers:master Feb 19, 2025
3 checks passed
@rainers
Copy link
Owner

rainers commented Feb 19, 2025

Thanks.

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

Successfully merging this pull request may close these issues.

2 participants