-
Notifications
You must be signed in to change notification settings - Fork 116
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
Add support for Dwarf5 as emitted by gcc-11.2 #69
Changes from all commits
28d3fad
594cf2b
27a6223
f26b66e
c7c7dfe
13e0840
35c615b
13a21e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,81 @@ | |
struct OMFDirHeader; | ||
struct OMFDirEntry; | ||
|
||
typedef unsigned char byte; | ||
|
||
struct SymbolInfo | ||
{ | ||
int seg; | ||
unsigned long off; | ||
bool dllimport; | ||
}; | ||
|
||
struct PESection | ||
{ | ||
byte* base; | ||
unsigned long length; | ||
unsigned int secNo; | ||
|
||
PESection() | ||
: base(0) | ||
, length(0) | ||
, secNo(0) | ||
{ | ||
} | ||
|
||
byte* byteAt(unsigned int off) const | ||
{ | ||
return base + off; | ||
} | ||
|
||
byte* startByte() const | ||
{ | ||
return byteAt(0); | ||
} | ||
|
||
byte* endByte() const | ||
{ | ||
return byteAt(0) + length; | ||
} | ||
|
||
bool isPresent() const | ||
{ | ||
return base && length; | ||
} | ||
|
||
bool isPtrInside(const void *p) const | ||
{ | ||
auto pInt = (uintptr_t)p; | ||
return (pInt >= (uintptr_t)base && pInt < (uintptr_t)base + length); | ||
} | ||
|
||
unsigned int sectOff(void *p) const | ||
{ | ||
return (unsigned int)((uintptr_t)p - (uintptr_t)base); | ||
} | ||
}; | ||
|
||
// Define the list of interesting PE sections in one place so that we can | ||
// generate definitions needed to populate our pointers and reference each | ||
// section. | ||
|
||
#define SECTION_LIST() \ | ||
EXPANDSEC(debug_addr) \ | ||
EXPANDSEC(debug_info) \ | ||
EXPANDSEC(debug_abbrev) \ | ||
EXPANDSEC(debug_line) \ | ||
EXPANDSEC(debug_line_str) \ | ||
EXPANDSEC(debug_frame) \ | ||
EXPANDSEC(debug_str) \ | ||
EXPANDSEC(debug_str_offsets) \ | ||
EXPANDSEC(debug_loc) \ | ||
EXPANDSEC(debug_loclists) \ | ||
EXPANDSEC(debug_ranges) \ | ||
EXPANDSEC(debug_rnglists) \ | ||
EXPANDSEC(reloc) \ | ||
EXPANDSEC(text) | ||
|
||
|
||
#define IMGHDR(x) (hdr32 ? hdr32->x : hdr64->x) | ||
|
||
class PEImage : public LastError | ||
|
@@ -70,14 +138,15 @@ class PEImage : public LastError | |
bool save(const TCHAR* oname); | ||
|
||
bool replaceDebugSection (const void* data, int datalen, bool initCV); | ||
void initSec(PESection& peSec, int secNo) const; | ||
bool initCVPtr(bool initDbgDir); | ||
bool initDbgPtr(bool initDbgDir); | ||
bool initDWARFPtr(bool initDbgDir); | ||
bool initDWARFObject(); | ||
void initDWARFSegments(); | ||
bool relocateDebugLineInfo(unsigned int img_base); | ||
|
||
bool hasDWARF() const { return debug_line != 0; } | ||
bool hasDWARF() const { return debug_line.isPresent(); } | ||
bool isX64() const { return x64; } | ||
bool isDBG() const { return dbgfile; } | ||
|
||
|
@@ -131,23 +200,30 @@ class PEImage : public LastError | |
|
||
public: | ||
//dwarf | ||
char* debug_aranges; | ||
char* debug_pubnames; | ||
char* debug_pubtypes; | ||
char* debug_info; unsigned long debug_info_length; | ||
char* debug_abbrev; unsigned long debug_abbrev_length; | ||
char* debug_line; unsigned long debug_line_length; | ||
char* debug_line_str; unsigned long debug_line_str_length; | ||
char* debug_frame; unsigned long debug_frame_length; | ||
char* debug_str; | ||
char* debug_loc; unsigned long debug_loc_length; | ||
char* debug_ranges; unsigned long debug_ranges_length; | ||
char* reloc; unsigned long reloc_length; | ||
|
||
int linesSegment; | ||
int codeSegment; | ||
#define EXPANDSEC(name) PESection name; | ||
SECTION_LIST() | ||
#undef EXPANDSEC | ||
|
||
int cv_base; | ||
}; | ||
|
||
struct SectionDescriptor { | ||
const char *name; | ||
PESection PEImage::* pSec; | ||
}; | ||
|
||
#define EXPANDSEC(name) constexpr SectionDescriptor sec_desc_##name { "." #name, &PEImage::name }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cv2pdb is also compiled with Visual D, see https://ci.appveyor.com/project/rainers/visuald. The CI still uses VS2017, I'm not sure how well this works with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tested all the way back to VS2015 and this usage of constexpr is supported back there: Do you still want me to remove it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for verifying that it works in older VS, too. No need to change it then. |
||
SECTION_LIST() | ||
#undef EXPANDSEC | ||
|
||
constexpr const SectionDescriptor *sec_descriptors[] = | ||
{ | ||
#define EXPANDSEC(name) &sec_desc_##name, | ||
SECTION_LIST() | ||
#undef EXPANDSEC | ||
}; | ||
|
||
|
||
#undef SECTION_LIST | ||
|
||
#endif //__PEIMAGE_H__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in #68 (review), I like to review PRs commit by commit, and if there is too much in one single commit, it is easy for bugs to hide. I did not find any bug in this, but I would not be surprised if I missed any because of the different goals of this commit: dropping
debug_aranges
and friends, refactoringPESection
s, adding new ones, dropping commented-out code, adding debugging, etc ;-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your concern. I was mainly aiming here for a testable chunk which shouldn't introduce functional changes.
I have a different philosophy about code review: it's really only worthwhile for architectural analysis and for suggesting ways to improve the readability or understandability of code. For bugs, however, tests are the gold standard. Especially for code like this where an off-by-one error or subtle spec misreading can lead to wildly different results. I think we've seen over the decades that the "thousand eyes make bugs shallow" idea doesn't really work in practice.