Bug 1197377 - Read callgraph.txt line by line to avoid string size limits, r=terrence

This commit is contained in:
Steve Fink 2015-08-21 14:19:04 -07:00
parent 16c600936c
commit c9e335ccf2
2 changed files with 32 additions and 2 deletions

View File

@ -74,8 +74,9 @@ function loadCallgraph(file)
var suppressedFieldCalls = {};
var resolvedFunctions = {};
var textLines = snarf(file).split('\n');
for (var line of textLines) {
for (var line of readFileLines_gen(file)) {
line = line.replace(/\n/, "");
var match;
if (match = line.charAt(0) == "#" && /^\#(\d+) (.*)/.exec(line)) {
assert(functionNames.length == match[1]);

View File

@ -145,3 +145,32 @@ function xdbLibrary()
free_string: lib.declare("xdb_free", ctypes.default_abi, ctypes.void_t, ctypes.char.ptr)
};
}
function cLibrary()
{
var lib;
try {
lib = ctypes.open("libc.so.6");
} catch(e) {
lib = ctypes.open("libc.so");
}
return {
fopen: lib.declare("fopen", ctypes.default_abi, ctypes.void_t.ptr, ctypes.char.ptr, ctypes.char.ptr),
getline: lib.declare("getline", ctypes.default_abi, ctypes.ssize_t, ctypes.char.ptr.ptr, ctypes.size_t.ptr, ctypes.void_t.ptr),
fclose: lib.declare("fopen", ctypes.default_abi, ctypes.int, ctypes.void_t.ptr),
setvbuf: lib.declare("setvbuf", ctypes.default_abi, ctypes.int, ctypes.void_t.ptr, ctypes.char.ptr, ctypes.int, ctypes.size_t),
};
}
function* readFileLines_gen(filename)
{
var libc = cLibrary();
var linebuf = ctypes.char.array(4096)();
var bufsize = ctypes.size_t(4096);
var fp = libc.fopen(filename, "r");
var bufp = ctypes.char.ptr(linebuf.addressOfElement(0));
while (libc.getline(bufp.address(), bufsize.address(), fp) > 0)
yield bufp.readString();
libc.fclose(fp);
}