forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src, tools: add debug symbols for node internals
Those changes are the first steps towards allowing debug tools to navigate some of Node's internals strucutres, giving more possibilities to developers doing post-mortem debugging. One example of what can be achieved with the symbols added is a new command being developed for llnode, which prints information about handles and requests on the queue for a core dump file. Ref: nodejs/post-mortem#46
- Loading branch information
Matheus Marchini
committed
Aug 17, 2017
1 parent
60f2fa9
commit acf9da6
Showing
10 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#!/usr/bin/env python | ||
|
||
# | ||
# gen-postmortem-metadata.py output_file.cc | ||
# | ||
# Creates debugging symbols to help naviage Node's internals using post-mortem | ||
# debugging tools. | ||
# | ||
|
||
import sys | ||
|
||
|
||
class DebugSymbol(object): | ||
type_ = 'int' | ||
_PREFIX = 'nodedbg_' | ||
|
||
def __init__(self, name, value, headers=[], type_=None): | ||
self.name = name | ||
self.value = value | ||
self.headers = headers | ||
self.type_ = type_ or DebugSymbol.type_ | ||
|
||
@classmethod | ||
def get_headers(cls, debug_symbols): | ||
seen = set() | ||
seen_add = seen.add # faster than seen.add on each iteration | ||
headers = [debug_symbol.headers for debug_symbol in debug_symbols] | ||
headers = sum(headers, []) | ||
|
||
return [h for h in headers if not (h in seen or seen_add(h))] | ||
|
||
def __str__(self): | ||
return "{type} {prefix}{name} = {value};".format( | ||
type=self.type_, | ||
prefix=self._PREFIX, | ||
name=self.name, | ||
value=self.value, | ||
) | ||
|
||
|
||
debug_symbols = [ | ||
DebugSymbol( | ||
name="currentEnvironment", | ||
value="(uint64_t) &Environment::currentEnvironment", | ||
headers=["env.h"], | ||
type_="uint64_t", | ||
), | ||
DebugSymbol( | ||
name="class__BaseObject__persistant_handle", | ||
value="(size_t) &(((BaseObject*)0)->persistent())", | ||
headers=["base-object.h", "base-object-inl.h"], | ||
type_="size_t", | ||
), | ||
DebugSymbol( | ||
name="class__Environment__handleWrapQueue", | ||
value="(size_t) (((Environment*)0)->handle_wrap_queue())", | ||
headers=["env.h"], | ||
type_="size_t", | ||
), | ||
DebugSymbol( | ||
name="class__HandleWrap__node", | ||
value="(size_t) (((HandleWrap*)0)->handle_wrap_queue())", | ||
headers=["handle_wrap.h"], | ||
type_="size_t", | ||
), | ||
DebugSymbol( | ||
name="class__HandleWrapQueue__headOffset", | ||
value="(size_t) (((Environment::HandleWrapQueue*)0)->head())", | ||
headers=["env.h"], | ||
type_="size_t", | ||
), | ||
DebugSymbol( | ||
name="class__HandleWrapQueue__nextOffset", | ||
value="(size_t) (((ListNode<HandleWrap>*)0)->next())", | ||
headers=["handle_wrap.h", "util.h"], | ||
type_="size_t", | ||
), | ||
DebugSymbol( | ||
name="class__Environment__reqWrapQueue", | ||
value="(size_t) (((Environment*)0)->req_wrap_queue())", | ||
headers=["env.h"], | ||
type_="size_t", | ||
), | ||
DebugSymbol( | ||
name="class__ReqWrap__node", | ||
value="(size_t) (((ReqWrap<uv_req_t>*)0)->req_wrap_queue())", | ||
headers=["req-wrap.h"], | ||
type_="size_t", | ||
), | ||
DebugSymbol( | ||
name="class__ReqWrapQueue__headOffset", | ||
value="(size_t) (((Environment::ReqWrapQueue*)0)->head())", | ||
headers=["env.h"], | ||
type_="size_t", | ||
), | ||
DebugSymbol( | ||
name="class__ReqWrapQueue__nextOffset", | ||
value="(size_t) (((ListNode<ReqWrap<uv_req_t>>*)0)->next())", | ||
headers=["req-wrap.h", "util.h"], | ||
type_="size_t", | ||
), | ||
] | ||
|
||
|
||
template = ''' | ||
/* | ||
* This file is generated by {filename}. Do not edit directly. | ||
*/ | ||
{includes} | ||
using namespace node; | ||
extern "C" {{ | ||
{symbols} | ||
}} | ||
''' | ||
|
||
|
||
def create_symbols_file(): | ||
out = file(sys.argv[1], 'w') | ||
headers = DebugSymbol.get_headers(debug_symbols) | ||
includes = ['#include "{}"'.format(header) for header in headers] | ||
includes = "\n".join(includes) | ||
|
||
symbols = "\n".join([str(symbol) for symbol in debug_symbols]) | ||
|
||
out.write(template.format( | ||
filename=sys.argv[0], | ||
includes=includes, | ||
symbols=symbols, | ||
)) | ||
|
||
|
||
if (len(sys.argv) < 2): | ||
print('usage: %s output.cc' % sys.argv[0]) | ||
sys.exit(2) | ||
|
||
|
||
create_symbols_file() |