Skip to content

Commit

Permalink
meta: drop support for lldb 3.8
Browse files Browse the repository at this point in the history
PR-URL: nodejs#263
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
mmarchini committed Feb 25, 2019
1 parent c7ede80 commit ea06ef5
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 336 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ The following subcommands are supported:
findjsobjects -- List all object types and instance counts grouped by typename and sorted by instance count. Use
-d or --detailed to get an output grouped by type name, properties, and array length, as well as
more information regarding each type.
With lldb < 3.9, requires the `LLNODE_RANGESFILE` environment variable to be set to a file
containing memory ranges for the core file being debugged.
There are scripts for generating this file on Linux and Mac in the scripts directory of the llnode
repository.
findrefs -- Finds all the object properties which meet the search criteria.
The default is to list all the object properties that reference the specified value.
Flags:
Expand Down Expand Up @@ -341,7 +337,7 @@ TEST_LLDB_BINARY=`which lldb-4.0` npm run test-all
* `LLNODE_DEBUG=true` to see additional debug info from llnode
* `TEST_LLNODE_DEBUG=true` to see additional debug info coming from the tests
* `LLNODE_CORE=/path/to/core/dump LLNODE_NODE_EXE=/path/to/node LLNODE_NO_RANGES=true`
* `LLNODE_CORE=/path/to/core/dump LLNODE_NODE_EXE=/path/to/node`
to use a prepared core dump instead of generating one on-the-fly when running
the tests.
Expand All @@ -360,7 +356,6 @@ To debug `test/scan-test.js` with a prepared core dump:
LLNODE_DEBUG=true TEST_LLNODE_DEBUG=true \
LLNODE_CORE=/path/to/core/dump/of/inspect/scenario.js \
LLNODE_NODE_EXE=/path/to/node \
LLNODE_NO_RANGES=true \
node test/scan-test.js
```
Expand Down
78 changes: 0 additions & 78 deletions scripts/macho2segments.js

This file was deleted.

43 changes: 0 additions & 43 deletions scripts/otool2segments.py

This file was deleted.

43 changes: 0 additions & 43 deletions scripts/readelf2segments.py

This file was deleted.

9 changes: 0 additions & 9 deletions src/llnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
}
}

#ifdef LLDB_SBMemoryRegionInfoList_h_
// Heuristic: a PC in WX memory is almost certainly a V8 builtin.
// TODO(bnoordhuis) Find a way to map the PC to the builtin's name.
{
Expand All @@ -95,7 +94,6 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
continue;
}
}
#endif // LLDB_SBMemoryRegionInfoList_h_

// C++ stack frame.
SBStream desc;
Expand Down Expand Up @@ -445,13 +443,6 @@ bool PluginInitialize(SBDebugger d) {
"name and sorted by instance count. Use -d or --detailed to "
"get an output grouped by type name, properties, and array "
"length, as well as more information regarding each type.\n"
#ifndef LLDB_SBMemoryRegionInfoList_h_
"Requires `LLNODE_RANGESFILE` environment variable to be set "
"to a file containing memory ranges for the core file being "
"debugged.\n"
"There are scripts for generating this file on Linux and Mac "
"in the scripts directory of the llnode repository."
#endif // LLDB_SBMemoryRegionInfoList_h_
);

SBCommand settingsCmd =
Expand Down
114 changes: 4 additions & 110 deletions src/llscan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1420,48 +1420,22 @@ bool LLScan::ScanHeapForObjects(lldb::SBTarget target,
// Reload process anyway
process_ = target.GetProcess();

// Need to reload memory ranges (though this does assume the user has also
// updated
// LLNODE_RANGESFILE with data for the new dump or things won't match up).
// Need to reload memory regions.
if (target_ != target) {
ClearMemoryRanges();
ClearMapsToInstances();
ClearReferences();
target_ = target;
}

#ifndef LLDB_SBMemoryRegionInfoList_h_
/* Fall back to environment variable containing pre-parsed list of memory
* ranges. */
if (nullptr == ranges_) {
const char* segmentsfilename = getenv("LLNODE_RANGESFILE");

if (segmentsfilename == nullptr) {
result.SetError(
"No memory range information available for this process. Cannot scan "
"for objects.\n"
"Please set `LLNODE_RANGESFILE` environment variable\n");
return false;
}

if (!GenerateMemoryRanges(target, segmentsfilename)) {
result.SetError(
"No memory range information available for this process. Cannot scan "
"for objects.\n");
return false;
}
}
#endif // LLDB_SBMemoryRegionInfoList_h_

/* If we've reached here we have access to information about the valid memory
* ranges in the process and can scan for objects.
* regions in the process and can scan for objects.
*/

/* Populate the map of objects. */
if (mapstoinstances_.empty()) {
FindJSObjectsVisitor v(target, this);

ScanMemoryRanges(v);
ScanMemoryRegions(v);
}

return true;
Expand Down Expand Up @@ -1539,25 +1513,14 @@ inline static ByteOrder GetHostByteOrder() {
return u.b == 1 ? ByteOrder::eByteOrderBig : ByteOrder::eByteOrderLittle;
}

void LLScan::ScanMemoryRanges(FindJSObjectsVisitor& v) {
bool done = false;

void LLScan::ScanMemoryRegions(FindJSObjectsVisitor& v) {
const uint64_t addr_size = process_.GetAddressByteSize();
bool swap_bytes = process_.GetByteOrder() != GetHostByteOrder();

// Pages are usually around 1mb, so this should more than enough
const uint64_t block_size = 1024 * 1024 * addr_size;
unsigned char* block = new unsigned char[block_size];

#ifndef LLDB_SBMemoryRegionInfoList_h_
MemoryRange* head = ranges_;

while (head != nullptr && !done) {
uint64_t address = head->start_;
uint64_t len = head->length_;
head = head->next_;

#else // LLDB_SBMemoryRegionInfoList_h_
lldb::SBMemoryRegionInfoList memory_regions = process_.GetMemoryRegions();
lldb::SBMemoryRegionInfo region_info;

Expand All @@ -1571,7 +1534,6 @@ void LLScan::ScanMemoryRanges(FindJSObjectsVisitor& v) {
uint64_t address = region_info.GetRegionBase();
uint64_t len = region_info.GetRegionEnd() - region_info.GetRegionBase();

#endif // LLDB_SBMemoryRegionInfoList_h_
/* Brute force search - query every address - but allow the visitor code to
* say how far to move on so we don't read every byte.
*/
Expand Down Expand Up @@ -1614,7 +1576,6 @@ void LLScan::ScanMemoryRanges(FindJSObjectsVisitor& v) {
}

if (increment == 0) {
done = true;
break;
}
}
Expand All @@ -1623,73 +1584,6 @@ void LLScan::ScanMemoryRanges(FindJSObjectsVisitor& v) {
delete[] block;
}


/* Read a file of memory ranges parsed from the core dump.
* This is a work around for the lack of an API to get the memory ranges
* within lldb.
* There are scripts for generating this file on Mac and Linux stored in
* the scripts directory of the llnode repository.
* Export the name or full path to the ranges file in the LLNODE_RANGESFILE
* env var before starting lldb and loading the llnode plugin.
*/
bool LLScan::GenerateMemoryRanges(lldb::SBTarget target,
const char* segmentsfilename) {
std::ifstream input(segmentsfilename);

if (!input.is_open()) {
return false;
}

uint64_t address = 0;
uint64_t len = 0;

MemoryRange** tailptr = &ranges_;

lldb::addr_t address_byte_size = target.GetProcess().GetAddressByteSize();

while (input >> std::hex >> address >> std::hex >> len) {
/* Check if the range is accessible.
* The structure of a core file means if you check the start and the end of
* a range then the middle will be there, ranges are contiguous in the file,
* but cores often get truncated due to file size limits so ranges can be
* missing or truncated. Sometimes shared memory segments are omitted so
* it's also possible an entire section could be missing from the middle.
*/
lldb::SBError error;

target.GetProcess().ReadPointerFromMemory(address, error);
if (!error.Success()) {
/* Could not access first word, skip. */
continue;
}

target.GetProcess().ReadPointerFromMemory(
(address + len) - address_byte_size, error);
if (!error.Success()) {
/* Could not access last word, skip. */
continue;
}

MemoryRange* newRange = new MemoryRange(address, len);

*tailptr = newRange;
tailptr = &(newRange->next_);
}
return true;
}


void LLScan::ClearMemoryRanges() {
MemoryRange* head = ranges_;
while (head != nullptr) {
MemoryRange* range = head;
head = head->next_;
delete range;
}
ranges_ = nullptr;
}


void LLScan::ClearMapsToInstances() {
TypeRecord* t;
for (auto entry : mapstoinstances_) {
Expand Down
Loading

0 comments on commit ea06ef5

Please sign in to comment.