summaryrefslogtreecommitdiffstats
path: root/src/dumplines.cpp
diff options
context:
space:
mode:
authorRainer Schuetze <r.sagitario@gmx.de>2015-05-08 21:00:52 (GMT)
committerRainer Schuetze <r.sagitario@gmx.de>2015-05-08 21:00:52 (GMT)
commit7014d4546d7113aa21ec21b1a19293cacebc948a (patch)
tree8ab39f331250e0979de15fea4eb77866f62b6072 /src/dumplines.cpp
parent0f4103c3f5768945c8a207746d1cb52524303110 (diff)
downloadcv2pdb-7014d4546d7113aa21ec21b1a19293cacebc948a.zip
cv2pdb-7014d4546d7113aa21ec21b1a19293cacebc948a.tar.gz
cv2pdb-7014d4546d7113aa21ec21b1a19293cacebc948a.tar.bz2
- new tool dumplines to display the debug line number info
Diffstat (limited to 'src/dumplines.cpp')
-rw-r--r--src/dumplines.cpp139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/dumplines.cpp b/src/dumplines.cpp
new file mode 100644
index 0000000..1a33888
--- /dev/null
+++ b/src/dumplines.cpp
@@ -0,0 +1,139 @@
+// Convert DMD CodeView debug information to PDB files
+// Copyright (c) 2009-2010 by Rainer Schuetze, All Rights Reserved
+//
+// License for redistribution is given by the Artistic License 2.0
+// see file LICENSE for further details
+
+#include "PEImage.h"
+#include "cv2pdb.h"
+#include "symutil.h"
+
+#include <direct.h>
+
+double
+#include "../VERSION"
+;
+
+#ifdef UNICODE
+#define T_toupper towupper
+#define T_getdcwd _wgetdcwd
+#define T_strlen wcslen
+#define T_strcpy wcscpy
+#define T_strcat wcscat
+#define T_strstr wcsstr
+#define T_strtod wcstod
+#define T_strrchr wcsrchr
+#define T_unlink _wremove
+#define T_main wmain
+#define SARG "%S"
+#else
+#define T_toupper toupper
+#define T_getdcwd _getdcwd
+#define T_strlen strlen
+#define T_strcpy strcpy
+#define T_strcat strcat
+#define T_strstr strstr
+#define T_strtod strtod
+#define T_strrchr strrchr
+#define T_unlink unlink
+#define T_main main
+#define SARG "%s"
+#endif
+
+void fatal(const char *message, ...)
+{
+ va_list argptr;
+ va_start(argptr, message);
+ vprintf(message, argptr);
+ va_end(argptr);
+ printf("\n");
+ exit(1);
+}
+
+void makefullpath(TCHAR* pdbname)
+{
+ TCHAR* pdbstart = pdbname;
+ TCHAR fullname[260];
+ TCHAR* pfullname = fullname;
+
+ int drive = 0;
+ if (pdbname[0] && pdbname[1] == ':')
+ {
+ if (pdbname[2] == '\\' || pdbname[2] == '/')
+ return;
+ drive = T_toupper (pdbname[0]);
+ pdbname += 2;
+ }
+ else
+ {
+ drive = _getdrive();
+ }
+
+ if (*pdbname != '\\' && *pdbname != '/')
+ {
+ T_getdcwd(drive, pfullname, sizeof(fullname)/sizeof(fullname[0]) - 2);
+ pfullname += T_strlen(pfullname);
+ if (pfullname[-1] != '\\')
+ *pfullname++ = '\\';
+ }
+ else
+ {
+ *pfullname++ = 'a' - 1 + drive;
+ *pfullname++ = ':';
+ }
+ T_strcpy(pfullname, pdbname);
+ T_strcpy(pdbstart, fullname);
+
+ for(TCHAR*p = pdbstart; *p; p++)
+ if (*p == '/')
+ *p = '\\';
+
+ // remove relative parts "./" and "../"
+ while (TCHAR* p = T_strstr (pdbstart, TEXT("\\.\\")))
+ T_strcpy(p, p + 2);
+
+ while (TCHAR* p = T_strstr (pdbstart, TEXT("\\..\\")))
+ {
+ for (TCHAR* q = p - 1; q >= pdbstart; q--)
+ if (*q == '\\')
+ {
+ T_strcpy(q, p + 3);
+ break;
+ }
+ }
+}
+
+int dumpObjectFile(TCHAR* fname)
+{
+ PEImage img;
+ if (!img.readAll(fname))
+ fatal(SARG ": %s", fname, img.getLastError());
+
+ img.initDWARFObject();
+ if(img.debug_line)
+ {
+ if (!interpretDWARFLines(img, 0))
+ fatal(SARG ": cannot dump line numbers", fname);
+ }
+ else if (img.dumpDebugLineInfoOMF() < 0)
+ img.dumpDebugLineInfoCOFF();
+
+ return 0;
+}
+
+int T_main(int argc, TCHAR* argv[])
+{
+ if (argc < 2)
+ {
+ printf("Dump line information for object files in OMF/CV4, COFF/CV8 or COFF/DWARF format, Version %g\n", VERSION);
+ printf("Copyright (c) 2015 by Rainer Schuetze, All Rights Reserved\n");
+ printf("\n");
+ printf("License for redistribution is given by the Artistic License 2.0\n");
+ printf("see file LICENSE for further details\n");
+ printf("\n");
+ printf("usage: " SARG " <obj-file>\n", argv[0]);
+ return -1;
+ }
+
+ return dumpObjectFile(argv[1]);
+}