debugger support, continue

This commit is contained in:
Vadim Lopatin 2015-02-16 17:48:29 +03:00
parent baa1656de3
commit 6dd80be82d
3 changed files with 76 additions and 10 deletions

View File

@ -64,7 +64,7 @@
<doXGeneration>1</doXGeneration>
<xfilename>$(IntDir)\$(TargetName).json</xfilename>
<debuglevel>0</debuglevel>
<debugids />
<debugids>DebugInfo</debugids>
<versionlevel>0</versionlevel>
<versionids>Unicode USE_FREETYPE</versionids>
<dump_source>0</dump_source>

View File

@ -1,5 +1,6 @@
module ddebug.windows.debuginfo;
version(Windows):
import dlangui.core.logger;
import std.file;
import std.algorithm;
@ -49,13 +50,47 @@ struct Buffer {
ubyte[] sectionAt(uint pos) {
uint rva = uintAt(pos);
uint sz = uintAt(pos + 4);
Log.d("section rva=", rva, " sz=", sz);
if (!sz)
return null;
enforce(pos + sz <= buf.length, new FileFormatException("sectionAt: index is outside file range"));
return buf[rva .. rva + sz];
}
string stringzAt(uint pos, uint maxSize) {
char[] res;
for (uint p = pos; maxSize == 0 || p < pos + maxSize; p++) {
ubyte ch = ubyteAt(p);
if (!ch)
break;
res ~= ch;
}
return cast(string)res;
}
ubyte[] rangeAt(uint pos, uint size) {
Log.d("rangeAt: pos=", pos, " size=", size, " pos+size=", pos+size, " buf.len=", buf.length);
uint endp = pos + size;
//if (endp > buf.length)
// endp = cast(uint)buf.length;
enforce(pos <= endp, new FileFormatException("rangeAt: index is outside file range"));
return buf[pos .. endp];
}
}
struct Section {
string name;
uint vsize;
uint rva;
uint sz;
uint offset;
uint flags;
this(ref Buffer buf, uint pos) {
name = buf.stringzAt(pos, 8);
vsize = buf.uintAt(pos + 0x08);
rva = buf.uintAt(pos + 0x0C);
sz = buf.uintAt(pos + 0x10);
offset = buf.uintAt(pos + 0x14);
flags = buf.uintAt(pos + 0x28);
}
}
class OMFDebugInfo {
@ -66,11 +101,40 @@ class OMFDebugInfo {
data.buf = cast(ubyte[])std.file.read(filename);
data.check(0, ['M', 'Z']);
peoffset = data.uintAt(0x3c);
data.skip(peoffset);
data.check(0, ['P', 'E', 0, 0]);
ushort objectCount = data.ushortAt(0x06);
ushort flags = data.ushortAt(0x16);
ushort subsystem = data.ushortAt(0x5c);
Buffer pe;
pe.buf = data.buf[peoffset .. $];
//data.skip(peoffset);
pe.check(0, ['P', 'E', 0, 0]);
ushort objectCount = pe.ushortAt(0x06);
ushort flags = pe.ushortAt(0x16);
ushort subsystem = pe.ushortAt(0x5c);
uint coffRva = pe.uintAt(0x0c);
uint coffSize = pe.uintAt(0x10);
Log.d("subsystem: ", subsystem, " flags: ", flags, " coffRva:", coffRva, " coffSize:", coffSize);
//ubyte[] debugInfo = data.sectionAt(peoffset + 0xA8);
//ubyte[] exportInfo = data.sectionAt(peoffset + 0x78);
//ubyte[] importInfo = data.sectionAt(peoffset + 0x7c);
//ubyte[] resInfo = data.sectionAt(peoffset + 0x88);
//Buffer debugHeader;
//debugHeader.buf = debugInfo;
//uint debugType = debugHeader.uintAt(0x0C);
//uint debugSize = debugHeader.uintAt(0x10);
//uint debugRva = debugHeader.uintAt(0x14);
//uint debugSeek = debugHeader.uintAt(0x18);
//Log.d("debugInfo[", debugInfo.length, "] type=", debugType, " debugSize=", debugSize, " rva=", debugRva, " seek=", debugSeek, " seek-rva=");
//ubyte[] debugRaw = data.rangeAt(debugSeek, debugSize);
//Log.d("debugRaw: ", debugRaw);
ubyte[] debugData;
for (int i = 0; i < objectCount; i++) {
Section section = Section(data, peoffset + 0xF8 + i * 0x28);
Log.d("section ", section.name, " rva=", section.rva, " sz=", section.sz, " offset=", section.offset);
if (section.name.equal(".debug"))
debugData = data.rangeAt(section.offset, section.sz);
}
if (debugData) {
string debugName = cast(string)debugData[1.. debugData[0] + 1];
Log.d("Found debug data: name=", debugName, " sz=", debugData.length);
}
return true;
} catch (Exception e) {
throw new FileFormatException(e);

View File

@ -43,9 +43,11 @@ extern (C) int UIAppMain(string[] args) {
//import ddc.lexer.tokenizer;
//runTokenizerTest();
debug(DebugInfo) {
import ddebug.windows.debuginfo;
import std.file;
debugInfoTest(thisExePath);
version(Windows) {
import ddebug.windows.debuginfo;
import std.file;
debugInfoTest(thisExePath);
}
}
// create window