Skip to content

[meta] Add support for CodeView, the MSVC-compatible debug information format #12655

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

Closed
timurrrr opened this issue Mar 16, 2012 · 7 comments
Closed
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category

Comments

@timurrrr
Copy link
Contributor

Bugzilla Link 12283
Resolution FIXED
Resolved on Jun 15, 2016 19:52
Version trunk
OS Windows NT
Blocks llvm/llvm-bugzilla-archive#13707
CC @amccarth-google,@asl,@majnemer,@echristo,@tritao,@tkremenek,@rnk

Extended Description

$ clang.exe -v
clang version 3.1 (trunk 152788)
Target: i686-pc-win32
Thread model: posix

$ cl /nologo /Zi debug_info.c dbghelp.lib && debug_info.exe
debug_info.c
#​00 main debug_info.c:12
#​01 __tmainCRTStartup f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c:266
#​02 BaseThreadInitThunk+0x00000012
#​03 RtlInitializeExceptionChain+0x00000063
#​04 RtlInitializeExceptionChain+0x00000036
Done

$ clang.exe -g debug_info.c "C:\Program Files\Microsoft SDKs\Windows\v7.0\Lib\dbghelp.lib" && a.out
#​00
#​01
#​02 BaseThreadInitThunk+0x00000012
#​03 RtlInitializeExceptionChain+0x00000063
#​04 RtlInitializeExceptionChain+0x00000036
Done

$ more debug_info.c
#include <windows.h>

#include <dbghelp.h>
#include <stdio.h>

#pragma comment(lib, "dbghelp.lib")

#define CHECK(x) do { if (!(x)) { printf("%s failed\n", #x); abort(); } } while(0)

int main(void) {
void *stacktrace[16];
size_t n, count = CaptureStackBackTrace(0, 16, stacktrace, NULL);
HANDLE proc = GetCurrentProcess();
CHECK(SymInitialize(proc, NULL, TRUE));

for (n = 0; n < 16 && n < count; ++n) {
// See http://msdn.microsoft.com/en-us/library/ms680578(VS.85).aspx
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(CHAR)];
PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer;
IMAGEHLP_LINE64 info;
DWORD64 offset = 0;
DWORD unused;
BOOL got_objname, got_fileline;

DWORD64 addr = (DWORD64)stacktrace[n];

symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
symbol->MaxNameLen = MAX_SYM_NAME;
got_objname = SymFromAddr(proc, addr, &offset, symbol);
info.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
got_fileline = SymGetLineFromAddr64(proc, addr, &unused, &info);
if (got_fileline) {
  printf(" #%02d %s %s:%ld\n", n, symbol->Name, info.FileName, info.LineNumber);
} else if (got_objname) {
  printf(" #%02d %s+0x%p\n", n, symbol->Name, (void*)offset);
} else {
  printf(" #%02d <no info>\n", n);
}

}
printf("Done\n");
return 0;
}

@timurrrr
Copy link
Contributor Author

btw, clang+link build has at least some info:

$ clang.exe -c -g debug_info.c && link /nologo /debug debug_info.o dbghelp.lib libcmt.lib && debug_info.exe
#​00 main+0x00000044
#​01 __tmainCRTStartup f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c:266
#​02 BaseThreadInitThunk+0x00000012
#​03 RtlInitializeExceptionChain+0x00000063
#​04 RtlInitializeExceptionChain+0x00000036
Done

@asl
Copy link
Collaborator

asl commented Mar 16, 2012

Does dbghelp support DWARF-based debug info? I'd bet - not. clang + link just provide you the debug info present in MS CRT libs / objects.

@asl
Copy link
Collaborator

asl commented Mar 16, 2012

I changed the title of the PR. Maybe someone someday will implement emission of debug info in VC format.

@tritao
Copy link
Mannequin

tritao mannequin commented Dec 27, 2012

Kai posted a patch with CodeView debug information emission, which would be a very good first step to fix this bug.

http://llvm-reviews.chandlerc.com/D165

@rnk
Copy link
Collaborator

rnk commented Jun 16, 2016

This is actually getting implemented, and I'd like to make this the meta-tracking bug for the support. Please file CodeView issues and mark them as blocking this meta bug so we can track them.

The current status is that using 'clang -g -gcodeview' (TODO: make -gcodeview imply -g) or 'clang-cl /Zi' or 'clang-cl /Z7' will emit CodeView into COFF objects. We describe local variables, globals, and functions, but there are major gaps. /Zi-style emission of type info into PDBs is not on the immediate roadmap.

@rnk
Copy link
Collaborator

rnk commented Jun 16, 2016

Some of the original reporters and commenters may not want to receive updates, so I'm going to open a new meta bug and then mark everything blocked on that. The original intent of this bug was just to get backtraces, and we got that long ago.

You can get more updates over at https://llvm.org/bugs/show_bug.cgi?id=28154.

@tritao
Copy link
Mannequin

tritao mannequin commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#13707

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

3 participants