2018-08-16 17:59:38 +00:00
|
|
|
//===-- JSONUtils.cpp -------------------------------------------*- C++ -*-===//
|
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-08-16 17:59:38 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2018-11-05 22:55:30 +00:00
|
|
|
#include <algorithm>
|
2020-07-24 13:30:04 -07:00
|
|
|
#include <iomanip>
|
2023-01-07 13:43:00 -08:00
|
|
|
#include <optional>
|
2020-07-24 13:30:04 -07:00
|
|
|
#include <sstream>
|
Add "indexedVariables" to variables with lots of children.
Prior to this fix if we have a really large array or collection class, we would end up always creating all of the child variables for an array or collection class. If the number of children was very high this can cause delays when expanding variables. By adding the "indexedVariables" to variables with lots of children, we can keep good performance in the variables view at all times. This patch will add the "indexedVariables" key/value pair to any "Variable" JSON dictionairies when we have an array of synthetic child provider that will create more than 100 children.
We have to be careful to not call "uint32_t SBValue::GetNumChildren()" on any lldb::SBValue that we use because it can cause a class, struct or union to complete the type in order to be able to properly tell us how many children it has and this can be expensive if you have a lot of variables. By default LLDB won't need to complete a type if we have variables that are classes, structs or unions unless the user expands the variable in the variable view. So we try to only get the GetNumChildren() when we have an array, as this is a cheap operation, or a synthetic child provider, most of which are for showing collections that typically fall into this category. We add a variable reference, which indicates that something can be expanded, when the function "bool SBValue::MightHaveChildren()" is true as this call doesn't need to complete the type in order to return true. This way if no one ever expands class variables, we don't need to complete the type.
Differential Revision: https://reviews.llvm.org/D125347
2022-05-10 13:41:06 -07:00
|
|
|
#include <string.h>
|
2018-11-05 22:55:30 +00:00
|
|
|
|
2024-05-30 09:54:13 +02:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-08-16 17:59:38 +00:00
|
|
|
#include "llvm/Support/FormatAdapters.h"
|
2023-11-30 12:17:12 -08:00
|
|
|
#include "llvm/Support/FormatVariadic.h"
|
[lldb-vscode] Correctly return source mapped breakpoints for setBreakpoints request
Summary:
When using source maps for a breakpoint, in order to find the actual source that breakpoint has resolved, we
need to use a query similar to what CommandObjectSource::DumpLinesInSymbolContexts does, which is the logic
used by the CLI to display the source line at a given breakpoint. That's necessary because from a breakpoint
location you only have an address, which points to the original source location, not the source mapped one.
in the setBreakpoints request handler, we haven't been doing such query and we were returning the original
source location, which was breaking the UX of VSCode, as many breakpoints were being set but not displayed
in the source file next to each line. Besides, clicking the source path of a breakpoint in the breakpoints
view in the debug tab was not working for this case, as VSCode was trying to open a non-existent file, thus
showing an error to the user.
Ideally, we should do the query mentioned above to find the actual source location to respond to the IDE,
however, that query is expensive and users can have an arbitrary number of breakpoints set. As a simpler fix,
the request sent by VSCode already contains the full source path, which exists because the user set it from
the IDE itself, so we can simply reuse it instead of querying from the SB API.
I wrote a test for this, and found out that I had to move SetSourceMapFromArguments after RunInitCommands in
lldb-vscode.cpp, because an init command used in all tests is `settings clear -all`, which would clear the
source map unless specified after initCommands. And in any case, I think it makes sense to have initCommands
run before anything the debugger would do.
Reviewers: clayborg, kusmour, labath, aadsm
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D76968
2020-03-27 19:31:14 -07:00
|
|
|
#include "llvm/Support/Path.h"
|
2020-04-28 13:13:45 +02:00
|
|
|
#include "llvm/Support/ScopedPrinter.h"
|
2018-08-16 17:59:38 +00:00
|
|
|
|
|
|
|
|
#include "lldb/API/SBBreakpoint.h"
|
|
|
|
|
#include "lldb/API/SBBreakpointLocation.h"
|
2021-04-21 15:06:44 -07:00
|
|
|
#include "lldb/API/SBDeclaration.h"
|
[lldb-vscode] Send Selected Statistics Dump in Terminated Event
This patch will gather debug info & breakpoint info from the statistics dump (from `(SBTarget.GetStatistics())` func) and send to DAP in terminated event.
The statistics content can be huge (especially the `modules`) and dumping in full JSON can create delay in the IDE's debugging UI. (For more details, please read: https://github.com/llvm/llvm-project/commit/7bbd0fba986c241162b77b7e424ad82bc7e17b41 ). Hence, we will filter out large contents before returning it in terminated event.
It will keep all the metadata fields (those starts with "total"). For large contents, it uses the opt-out strategy. Currently it only removes the "modules" field. This way every time a new top-level field being added, we will be able to capture them from DAP log without changing lldb-vscode.
The DAP terminated event should look like
```
{
"event":"terminated",
"seq":0,
"statistics": {
"memory": <JSON string>
"targets": <JSON string>, // it's a JSON array, breakpoints info included in each target
<metadata_key: value> // pairs
},
"type":"event"
}
```
All the info above will be append to statistics field in the terminated event
Test Plan
Debugged a simple hello world program from VSCode. Exit debug session in two ways: 1) run to program exit; 2) user initiated debug session end (quit debugging before program exit).
Check DAP log and see both debug sessions have statistics returned in terminated event.
Here's an example when debugging the test program:
```
{"event":"terminated","seq":0,"statistics":{"memory":"{\"strings\":{\"bytesTotal\":1843200,\"bytesUnused\":897741,\"bytesUsed\":945459}}","targets":"[{\"breakpoints\":[{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"NameMask\":[56],\"Offset\":0,\"SkipPrologue\":true,\"SymbolNames\":[\"foo\"]},\"Type\":\"SymbolName\"},\"Hardware\":false,\"Names\":[\"vscode\"],\"SearchFilter\":{\"Options\":{},\"Type\":\"Unconstrained\"}}},\"id\":1,\"internal\":false,\"numLocations\":1,\"numResolvedLocations\":1,\"resolveTime\":0.002232},{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"Column\":0,\"Exact\":false,\"FileName\":\"/data/users/wanyi/llvm-sand/external/llvm-project/lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp\",\"Inlines\":true,\"LineNumber\":5,\"Offset\":0,\"SkipPrologue\":true},\"Type\":\"FileAndLine\"},\"Hardware\":false,\"Names\":[\"vscode\"],\"SearchFilter\":{\"Options\":{},\"Type\":\"Unconstrained\"}}},\"id\":2,\"internal\":false,\"numLocations\":0,\"numResolvedLocations\":0,\"resolveTime\":0.23203799999999999},{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"Language\":\"c\",\"NameMask\":[4,4,4,4,4,4],\"Offset\":0,\"SkipPrologue\":false,\"SymbolNames\":[\"_dl_debug_state\",\"rtld_db_dlactivity\",\"__dl_rtld_db_dlactivity\",\"r_debug_state\",\"_r_debug_state\",\"_rtld_debug_state\"]},\"Type\":\"SymbolName\"},\"Hardware\":false,\"SearchFilter\":{\"Options\":{\"ModuleList\":[\"/usr/lib64/ld-2.28.so\"]},\"Type\":\"Modules\"}}},\"id\":-1,\"internal\":true,\"kindDescription\":\"shared-library-event\",\"numLocations\":1,\"numResolvedLocations\":1,\"resolveTime\":0.00026699999999999998}],\"expressionEvaluation\":{\"failures\":0,\"successes\":0},\"firstStopTime\":0.087458974999999994,\"frameVariable\":{\"failures\":0,\"successes\":0},\"launchOrAttachTime\":0.052953161999999998,\"moduleIdentifiers\":[94554748126576,94554747837792,94554747149216,139800112130176,139800112161056,139800112206064,139800112340224,139800112509552,139800112236528],\"signals\":[{\"SIGSTOP\":1}],\"sourceMapDeduceCount\":0,\"stopCount\":8,\"targetCreateTime\":0.00057700000000000004,\"totalBreakpointResolveTime\":0.234537}]","totalDebugInfoByteSize":1668056,"totalDebugInfoEnabled":3,"totalDebugInfoIndexLoadedFromCache":0,"totalDebugInfoIndexSavedToCache":0,"totalDebugInfoIndexTime":0.027963000000000002,"totalDebugInfoParseTime":0.34354800000000002,"totalModuleCount":10,"totalModuleCountHasDebugInfo":3,"totalSymbolTableIndexTime":0.056050000000000003,"totalSymbolTableParseTime":0.23930000000000001,"totalSymbolTableStripped":0,"totalSymbolTablesLoadedFromCache":0,"totalSymbolTablesSavedToCache":0},"type":"event"}
```
Differential Revision: https://reviews.llvm.org/D137665
2022-09-10 11:27:09 -07:00
|
|
|
#include "lldb/API/SBStringList.h"
|
|
|
|
|
#include "lldb/API/SBStructuredData.h"
|
2018-08-16 17:59:38 +00:00
|
|
|
#include "lldb/API/SBValue.h"
|
2018-08-16 18:24:59 +00:00
|
|
|
#include "lldb/Host/PosixApi.h"
|
2018-08-16 17:59:38 +00:00
|
|
|
|
2023-10-19 09:48:54 -07:00
|
|
|
#include "DAP.h"
|
2018-08-16 17:59:38 +00:00
|
|
|
#include "ExceptionBreakpoint.h"
|
|
|
|
|
#include "JSONUtils.h"
|
|
|
|
|
#include "LLDBUtils.h"
|
|
|
|
|
|
2023-10-19 09:48:54 -07:00
|
|
|
namespace lldb_dap {
|
2018-08-16 17:59:38 +00:00
|
|
|
|
2018-11-15 19:49:57 +00:00
|
|
|
void EmplaceSafeString(llvm::json::Object &obj, llvm::StringRef key,
|
|
|
|
|
llvm::StringRef str) {
|
|
|
|
|
if (LLVM_LIKELY(llvm::json::isUTF8(str)))
|
|
|
|
|
obj.try_emplace(key, str.str());
|
|
|
|
|
else
|
|
|
|
|
obj.try_emplace(key, llvm::json::fixUTF8(str));
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 17:59:38 +00:00
|
|
|
llvm::StringRef GetAsString(const llvm::json::Value &value) {
|
|
|
|
|
if (auto s = value.getAsString())
|
|
|
|
|
return *s;
|
|
|
|
|
return llvm::StringRef();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets a string from a JSON object using the key, or returns an empty string.
|
2023-10-25 00:05:54 -04:00
|
|
|
llvm::StringRef GetString(const llvm::json::Object &obj, llvm::StringRef key,
|
|
|
|
|
llvm::StringRef defaultValue) {
|
2022-12-16 07:56:52 +00:00
|
|
|
if (std::optional<llvm::StringRef> value = obj.getString(key))
|
2020-04-28 13:13:45 +02:00
|
|
|
return *value;
|
2023-10-25 00:05:54 -04:00
|
|
|
return defaultValue;
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-25 00:05:54 -04:00
|
|
|
llvm::StringRef GetString(const llvm::json::Object *obj, llvm::StringRef key,
|
|
|
|
|
llvm::StringRef defaultValue) {
|
2018-08-16 17:59:38 +00:00
|
|
|
if (obj == nullptr)
|
2023-10-25 00:05:54 -04:00
|
|
|
return defaultValue;
|
2023-11-20 15:57:14 -08:00
|
|
|
return GetString(*obj, key, defaultValue);
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets an unsigned integer from a JSON object using the key, or returns the
|
|
|
|
|
// specified fail value.
|
|
|
|
|
uint64_t GetUnsigned(const llvm::json::Object &obj, llvm::StringRef key,
|
|
|
|
|
uint64_t fail_value) {
|
|
|
|
|
if (auto value = obj.getInteger(key))
|
|
|
|
|
return (uint64_t)*value;
|
|
|
|
|
return fail_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t GetUnsigned(const llvm::json::Object *obj, llvm::StringRef key,
|
|
|
|
|
uint64_t fail_value) {
|
|
|
|
|
if (obj == nullptr)
|
|
|
|
|
return fail_value;
|
|
|
|
|
return GetUnsigned(*obj, key, fail_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GetBoolean(const llvm::json::Object &obj, llvm::StringRef key,
|
|
|
|
|
bool fail_value) {
|
|
|
|
|
if (auto value = obj.getBoolean(key))
|
|
|
|
|
return *value;
|
|
|
|
|
if (auto value = obj.getInteger(key))
|
|
|
|
|
return *value != 0;
|
|
|
|
|
return fail_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GetBoolean(const llvm::json::Object *obj, llvm::StringRef key,
|
|
|
|
|
bool fail_value) {
|
|
|
|
|
if (obj == nullptr)
|
|
|
|
|
return fail_value;
|
|
|
|
|
return GetBoolean(*obj, key, fail_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t GetSigned(const llvm::json::Object &obj, llvm::StringRef key,
|
|
|
|
|
int64_t fail_value) {
|
|
|
|
|
if (auto value = obj.getInteger(key))
|
|
|
|
|
return *value;
|
|
|
|
|
return fail_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t GetSigned(const llvm::json::Object *obj, llvm::StringRef key,
|
|
|
|
|
int64_t fail_value) {
|
|
|
|
|
if (obj == nullptr)
|
|
|
|
|
return fail_value;
|
|
|
|
|
return GetSigned(*obj, key, fail_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ObjectContainsKey(const llvm::json::Object &obj, llvm::StringRef key) {
|
2018-12-15 00:15:33 +00:00
|
|
|
return obj.find(key) != obj.end();
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-16 22:56:20 +02:00
|
|
|
std::string EncodeMemoryReference(lldb::addr_t addr) {
|
|
|
|
|
return "0x" + llvm::utohexstr(addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<lldb::addr_t>
|
|
|
|
|
DecodeMemoryReference(llvm::StringRef memoryReference) {
|
|
|
|
|
if (!memoryReference.starts_with("0x"))
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
|
|
lldb::addr_t addr;
|
|
|
|
|
if (memoryReference.consumeInteger(0, addr))
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 17:59:38 +00:00
|
|
|
std::vector<std::string> GetStrings(const llvm::json::Object *obj,
|
|
|
|
|
llvm::StringRef key) {
|
|
|
|
|
std::vector<std::string> strs;
|
|
|
|
|
auto json_array = obj->getArray(key);
|
|
|
|
|
if (!json_array)
|
|
|
|
|
return strs;
|
|
|
|
|
for (const auto &value : *json_array) {
|
|
|
|
|
switch (value.kind()) {
|
|
|
|
|
case llvm::json::Value::String:
|
|
|
|
|
strs.push_back(value.getAsString()->str());
|
|
|
|
|
break;
|
|
|
|
|
case llvm::json::Value::Number:
|
2020-04-28 13:13:45 +02:00
|
|
|
case llvm::json::Value::Boolean:
|
|
|
|
|
strs.push_back(llvm::to_string(value));
|
2018-08-16 17:59:38 +00:00
|
|
|
break;
|
|
|
|
|
case llvm::json::Value::Null:
|
|
|
|
|
case llvm::json::Value::Object:
|
|
|
|
|
case llvm::json::Value::Array:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return strs;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-07 17:38:36 +01:00
|
|
|
std::unordered_map<std::string, std::string>
|
|
|
|
|
GetStringMap(const llvm::json::Object &obj, llvm::StringRef key) {
|
|
|
|
|
std::unordered_map<std::string, std::string> strs;
|
|
|
|
|
const auto *const json_object = obj.getObject(key);
|
|
|
|
|
if (!json_object)
|
|
|
|
|
return strs;
|
|
|
|
|
|
|
|
|
|
for (const auto &[key, value] : *json_object) {
|
|
|
|
|
switch (value.kind()) {
|
|
|
|
|
case llvm::json::Value::String:
|
|
|
|
|
strs.emplace(key.str(), value.getAsString()->str());
|
|
|
|
|
break;
|
|
|
|
|
case llvm::json::Value::Number:
|
|
|
|
|
case llvm::json::Value::Boolean:
|
|
|
|
|
strs.emplace(key.str(), llvm::to_string(value));
|
|
|
|
|
break;
|
|
|
|
|
case llvm::json::Value::Null:
|
|
|
|
|
case llvm::json::Value::Object:
|
|
|
|
|
case llvm::json::Value::Array:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return strs;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 14:12:30 -08:00
|
|
|
static bool IsClassStructOrUnionType(lldb::SBType t) {
|
|
|
|
|
return (t.GetTypeClass() & (lldb::eTypeClassUnion | lldb::eTypeClassStruct |
|
2024-05-02 14:20:19 -04:00
|
|
|
lldb::eTypeClassArray)) != 0;
|
2024-01-12 14:12:30 -08:00
|
|
|
}
|
|
|
|
|
|
2023-09-06 17:13:27 -04:00
|
|
|
/// Create a short summary for a container that contains the summary of its
|
|
|
|
|
/// first children, so that the user can get a glimpse of its contents at a
|
|
|
|
|
/// glance.
|
|
|
|
|
static std::optional<std::string>
|
2023-09-20 10:23:41 -04:00
|
|
|
TryCreateAutoSummaryForContainer(lldb::SBValue &v) {
|
2023-09-11 17:00:01 -04:00
|
|
|
// We gate this feature because it performs GetNumChildren(), which can
|
|
|
|
|
// cause performance issues because LLDB needs to complete possibly huge
|
|
|
|
|
// types.
|
2023-10-19 09:48:54 -07:00
|
|
|
if (!g_dap.enable_auto_variable_summaries)
|
2023-09-11 17:00:01 -04:00
|
|
|
return std::nullopt;
|
|
|
|
|
|
2023-09-20 10:23:41 -04:00
|
|
|
if (!v.MightHaveChildren())
|
2023-09-06 17:13:27 -04:00
|
|
|
return std::nullopt;
|
|
|
|
|
/// As this operation can be potentially slow, we limit the total time spent
|
|
|
|
|
/// fetching children to a few ms.
|
|
|
|
|
const auto max_evaluation_time = std::chrono::milliseconds(10);
|
|
|
|
|
/// We don't want to generate a extremely long summary string, so we limit its
|
|
|
|
|
/// length.
|
|
|
|
|
const size_t max_length = 32;
|
|
|
|
|
|
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
|
|
|
|
std::string summary;
|
|
|
|
|
llvm::raw_string_ostream os(summary);
|
|
|
|
|
os << "{";
|
|
|
|
|
|
|
|
|
|
llvm::StringRef separator = "";
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0, e = v.GetNumChildren(); i < e; ++i) {
|
|
|
|
|
// If we reached the time limit or exceeded the number of characters, we
|
|
|
|
|
// dump `...` to signal that there are more elements in the collection.
|
|
|
|
|
if (summary.size() > max_length ||
|
|
|
|
|
(std::chrono::steady_clock::now() - start) > max_evaluation_time) {
|
|
|
|
|
os << separator << "...";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
lldb::SBValue child = v.GetChildAtIndex(i);
|
|
|
|
|
|
|
|
|
|
if (llvm::StringRef name = child.GetName(); !name.empty()) {
|
2024-01-12 14:12:30 -08:00
|
|
|
llvm::StringRef desc;
|
2023-09-06 17:13:27 -04:00
|
|
|
if (llvm::StringRef summary = child.GetSummary(); !summary.empty())
|
2024-01-12 14:12:30 -08:00
|
|
|
desc = summary;
|
|
|
|
|
else if (llvm::StringRef value = child.GetValue(); !value.empty())
|
|
|
|
|
desc = value;
|
|
|
|
|
else if (IsClassStructOrUnionType(child.GetType()))
|
|
|
|
|
desc = "{...}";
|
2023-09-06 17:13:27 -04:00
|
|
|
else
|
2024-01-12 14:12:30 -08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// If the child is an indexed entry, we don't show its index to save
|
|
|
|
|
// characters.
|
|
|
|
|
if (name.starts_with("["))
|
|
|
|
|
os << separator << desc;
|
|
|
|
|
else
|
|
|
|
|
os << separator << name << ":" << desc;
|
|
|
|
|
separator = ", ";
|
2023-09-06 17:13:27 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
os << "}";
|
|
|
|
|
|
|
|
|
|
if (summary == "{...}" || summary == "{}")
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
return summary;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 10:23:41 -04:00
|
|
|
/// Try to create a summary string for the given value that doesn't have a
|
|
|
|
|
/// summary of its own.
|
|
|
|
|
static std::optional<std::string> TryCreateAutoSummary(lldb::SBValue value) {
|
2023-10-19 09:48:54 -07:00
|
|
|
if (!g_dap.enable_auto_variable_summaries)
|
2023-09-20 10:23:41 -04:00
|
|
|
return std::nullopt;
|
2023-09-06 17:13:27 -04:00
|
|
|
|
2023-09-20 10:23:41 -04:00
|
|
|
// We use the dereferenced value for generating the summary.
|
|
|
|
|
if (value.GetType().IsPointerType() || value.GetType().IsReferenceType())
|
|
|
|
|
value = value.Dereference();
|
2023-09-06 17:13:27 -04:00
|
|
|
|
2023-09-20 10:23:41 -04:00
|
|
|
// We only support auto summaries for containers.
|
|
|
|
|
return TryCreateAutoSummaryForContainer(value);
|
2023-09-06 17:13:27 -04:00
|
|
|
}
|
|
|
|
|
|
2018-08-16 17:59:38 +00:00
|
|
|
void FillResponse(const llvm::json::Object &request,
|
|
|
|
|
llvm::json::Object &response) {
|
|
|
|
|
// Fill in all of the needed response fields to a "request" and set "success"
|
|
|
|
|
// to true by default.
|
|
|
|
|
response.try_emplace("type", "response");
|
|
|
|
|
response.try_emplace("seq", (int64_t)0);
|
2018-11-15 19:49:57 +00:00
|
|
|
EmplaceSafeString(response, "command", GetString(request, "command"));
|
2018-08-16 17:59:38 +00:00
|
|
|
const int64_t seq = GetSigned(request, "seq", 0);
|
|
|
|
|
response.try_emplace("request_seq", seq);
|
|
|
|
|
response.try_emplace("success", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "Scope": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "A Scope is a named container for variables. Optionally
|
|
|
|
|
// a scope can map to a source or a range within a source.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "name": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "Name of the scope such as 'Arguments', 'Locals'."
|
|
|
|
|
// },
|
2021-11-08 15:44:31 +01:00
|
|
|
// "presentationHint": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "An optional hint for how to present this scope in the
|
|
|
|
|
// UI. If this attribute is missing, the scope is shown
|
|
|
|
|
// with a generic UI.",
|
|
|
|
|
// "_enum": [ "arguments", "locals", "registers" ],
|
|
|
|
|
// },
|
2018-08-16 17:59:38 +00:00
|
|
|
// "variablesReference": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "The variables of this scope can be retrieved by
|
|
|
|
|
// passing the value of variablesReference to the
|
|
|
|
|
// VariablesRequest."
|
|
|
|
|
// },
|
|
|
|
|
// "namedVariables": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "The number of named variables in this scope. The
|
|
|
|
|
// client can use this optional information to present
|
|
|
|
|
// the variables in a paged UI and fetch them in chunks."
|
|
|
|
|
// },
|
|
|
|
|
// "indexedVariables": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "The number of indexed variables in this scope. The
|
|
|
|
|
// client can use this optional information to present
|
|
|
|
|
// the variables in a paged UI and fetch them in chunks."
|
|
|
|
|
// },
|
|
|
|
|
// "expensive": {
|
|
|
|
|
// "type": "boolean",
|
|
|
|
|
// "description": "If true, the number of variables in this scope is
|
|
|
|
|
// large or expensive to retrieve."
|
|
|
|
|
// },
|
|
|
|
|
// "source": {
|
|
|
|
|
// "$ref": "#/definitions/Source",
|
|
|
|
|
// "description": "Optional source for this scope."
|
|
|
|
|
// },
|
|
|
|
|
// "line": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "Optional start line of the range covered by this
|
|
|
|
|
// scope."
|
|
|
|
|
// },
|
|
|
|
|
// "column": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "Optional start column of the range covered by this
|
|
|
|
|
// scope."
|
|
|
|
|
// },
|
|
|
|
|
// "endLine": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "Optional end line of the range covered by this scope."
|
|
|
|
|
// },
|
|
|
|
|
// "endColumn": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "Optional end column of the range covered by this
|
|
|
|
|
// scope."
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "name", "variablesReference", "expensive" ]
|
|
|
|
|
// }
|
|
|
|
|
llvm::json::Value CreateScope(const llvm::StringRef name,
|
|
|
|
|
int64_t variablesReference,
|
|
|
|
|
int64_t namedVariables, bool expensive) {
|
|
|
|
|
llvm::json::Object object;
|
2018-11-15 19:49:57 +00:00
|
|
|
EmplaceSafeString(object, "name", name.str());
|
2021-11-08 15:44:31 +01:00
|
|
|
|
2023-10-19 09:48:54 -07:00
|
|
|
// TODO: Support "arguments" scope. At the moment lldb-dap includes the
|
2021-11-08 15:44:31 +01:00
|
|
|
// arguments into the "locals" scope.
|
|
|
|
|
if (variablesReference == VARREF_LOCALS) {
|
|
|
|
|
object.try_emplace("presentationHint", "locals");
|
|
|
|
|
} else if (variablesReference == VARREF_REGS) {
|
|
|
|
|
object.try_emplace("presentationHint", "registers");
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 17:59:38 +00:00
|
|
|
object.try_emplace("variablesReference", variablesReference);
|
|
|
|
|
object.try_emplace("expensive", expensive);
|
|
|
|
|
object.try_emplace("namedVariables", namedVariables);
|
|
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "Breakpoint": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "Information about a Breakpoint created in setBreakpoints
|
|
|
|
|
// or setFunctionBreakpoints.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "id": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "An optional unique identifier for the breakpoint."
|
|
|
|
|
// },
|
|
|
|
|
// "verified": {
|
|
|
|
|
// "type": "boolean",
|
|
|
|
|
// "description": "If true breakpoint could be set (but not necessarily
|
|
|
|
|
// at the desired location)."
|
|
|
|
|
// },
|
|
|
|
|
// "message": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "An optional message about the state of the breakpoint.
|
|
|
|
|
// This is shown to the user and can be used to explain
|
|
|
|
|
// why a breakpoint could not be verified."
|
|
|
|
|
// },
|
|
|
|
|
// "source": {
|
|
|
|
|
// "$ref": "#/definitions/Source",
|
|
|
|
|
// "description": "The source where the breakpoint is located."
|
|
|
|
|
// },
|
|
|
|
|
// "line": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "The start line of the actual range covered by the
|
|
|
|
|
// breakpoint."
|
|
|
|
|
// },
|
|
|
|
|
// "column": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "An optional start column of the actual range covered
|
|
|
|
|
// by the breakpoint."
|
|
|
|
|
// },
|
|
|
|
|
// "endLine": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "An optional end line of the actual range covered by
|
|
|
|
|
// the breakpoint."
|
|
|
|
|
// },
|
|
|
|
|
// "endColumn": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "An optional end column of the actual range covered by
|
|
|
|
|
// the breakpoint. If no end line is given, then the end
|
|
|
|
|
// column is assumed to be in the start line."
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "verified" ]
|
|
|
|
|
// }
|
2024-02-13 11:38:02 -05:00
|
|
|
llvm::json::Value CreateBreakpoint(BreakpointBase *bp,
|
2023-01-07 14:18:35 -08:00
|
|
|
std::optional<llvm::StringRef> request_path,
|
2023-07-06 15:54:13 -04:00
|
|
|
std::optional<uint32_t> request_line,
|
|
|
|
|
std::optional<uint32_t> request_column) {
|
2018-08-16 17:59:38 +00:00
|
|
|
llvm::json::Object object;
|
[lldb-vscode] Correctly return source mapped breakpoints for setBreakpoints request
Summary:
When using source maps for a breakpoint, in order to find the actual source that breakpoint has resolved, we
need to use a query similar to what CommandObjectSource::DumpLinesInSymbolContexts does, which is the logic
used by the CLI to display the source line at a given breakpoint. That's necessary because from a breakpoint
location you only have an address, which points to the original source location, not the source mapped one.
in the setBreakpoints request handler, we haven't been doing such query and we were returning the original
source location, which was breaking the UX of VSCode, as many breakpoints were being set but not displayed
in the source file next to each line. Besides, clicking the source path of a breakpoint in the breakpoints
view in the debug tab was not working for this case, as VSCode was trying to open a non-existent file, thus
showing an error to the user.
Ideally, we should do the query mentioned above to find the actual source location to respond to the IDE,
however, that query is expensive and users can have an arbitrary number of breakpoints set. As a simpler fix,
the request sent by VSCode already contains the full source path, which exists because the user set it from
the IDE itself, so we can simply reuse it instead of querying from the SB API.
I wrote a test for this, and found out that I had to move SetSourceMapFromArguments after RunInitCommands in
lldb-vscode.cpp, because an init command used in all tests is `settings clear -all`, which would clear the
source map unless specified after initCommands. And in any case, I think it makes sense to have initCommands
run before anything the debugger would do.
Reviewers: clayborg, kusmour, labath, aadsm
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D76968
2020-03-27 19:31:14 -07:00
|
|
|
if (request_path)
|
|
|
|
|
object.try_emplace("source", CreateSource(*request_path));
|
2024-02-13 11:38:02 -05:00
|
|
|
bp->CreateJsonObject(object);
|
[lldb-vscode] Correctly return source mapped breakpoints for setBreakpoints request
Summary:
When using source maps for a breakpoint, in order to find the actual source that breakpoint has resolved, we
need to use a query similar to what CommandObjectSource::DumpLinesInSymbolContexts does, which is the logic
used by the CLI to display the source line at a given breakpoint. That's necessary because from a breakpoint
location you only have an address, which points to the original source location, not the source mapped one.
in the setBreakpoints request handler, we haven't been doing such query and we were returning the original
source location, which was breaking the UX of VSCode, as many breakpoints were being set but not displayed
in the source file next to each line. Besides, clicking the source path of a breakpoint in the breakpoints
view in the debug tab was not working for this case, as VSCode was trying to open a non-existent file, thus
showing an error to the user.
Ideally, we should do the query mentioned above to find the actual source location to respond to the IDE,
however, that query is expensive and users can have an arbitrary number of breakpoints set. As a simpler fix,
the request sent by VSCode already contains the full source path, which exists because the user set it from
the IDE itself, so we can simply reuse it instead of querying from the SB API.
I wrote a test for this, and found out that I had to move SetSourceMapFromArguments after RunInitCommands in
lldb-vscode.cpp, because an init command used in all tests is `settings clear -all`, which would clear the
source map unless specified after initCommands. And in any case, I think it makes sense to have initCommands
run before anything the debugger would do.
Reviewers: clayborg, kusmour, labath, aadsm
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D76968
2020-03-27 19:31:14 -07:00
|
|
|
// We try to add request_line as a fallback
|
|
|
|
|
if (request_line)
|
|
|
|
|
object.try_emplace("line", *request_line);
|
2023-07-06 15:54:13 -04:00
|
|
|
if (request_column)
|
|
|
|
|
object.try_emplace("column", *request_column);
|
2018-08-16 17:59:38 +00:00
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:30:04 -07:00
|
|
|
static uint64_t GetDebugInfoSizeInSection(lldb::SBSection section) {
|
|
|
|
|
uint64_t debug_info_size = 0;
|
|
|
|
|
llvm::StringRef section_name(section.GetName());
|
2023-12-16 14:39:37 -08:00
|
|
|
if (section_name.starts_with(".debug") ||
|
|
|
|
|
section_name.starts_with("__debug") ||
|
|
|
|
|
section_name.starts_with(".apple") || section_name.starts_with("__apple"))
|
2020-07-24 13:30:04 -07:00
|
|
|
debug_info_size += section.GetFileByteSize();
|
|
|
|
|
size_t num_sub_sections = section.GetNumSubSections();
|
|
|
|
|
for (size_t i = 0; i < num_sub_sections; i++) {
|
|
|
|
|
debug_info_size +=
|
|
|
|
|
GetDebugInfoSizeInSection(section.GetSubSectionAtIndex(i));
|
|
|
|
|
}
|
|
|
|
|
return debug_info_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint64_t GetDebugInfoSize(lldb::SBModule module) {
|
|
|
|
|
uint64_t debug_info_size = 0;
|
|
|
|
|
size_t num_sections = module.GetNumSections();
|
|
|
|
|
for (size_t i = 0; i < num_sections; i++) {
|
|
|
|
|
debug_info_size += GetDebugInfoSizeInSection(module.GetSectionAtIndex(i));
|
|
|
|
|
}
|
|
|
|
|
return debug_info_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::string ConvertDebugInfoSizeToString(uint64_t debug_info) {
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
oss << std::fixed << std::setprecision(1);
|
|
|
|
|
if (debug_info < 1024) {
|
|
|
|
|
oss << debug_info << "B";
|
|
|
|
|
} else if (debug_info < 1024 * 1024) {
|
|
|
|
|
double kb = double(debug_info) / 1024.0;
|
|
|
|
|
oss << kb << "KB";
|
|
|
|
|
} else if (debug_info < 1024 * 1024 * 1024) {
|
|
|
|
|
double mb = double(debug_info) / (1024.0 * 1024.0);
|
|
|
|
|
oss << mb << "MB";
|
|
|
|
|
} else {
|
|
|
|
|
double gb = double(debug_info) / (1024.0 * 1024.0 * 1024.0);
|
|
|
|
|
oss << gb << "GB";
|
|
|
|
|
}
|
|
|
|
|
return oss.str();
|
|
|
|
|
}
|
2020-07-13 12:10:49 -07:00
|
|
|
llvm::json::Value CreateModule(lldb::SBModule &module) {
|
|
|
|
|
llvm::json::Object object;
|
|
|
|
|
if (!module.IsValid())
|
|
|
|
|
return llvm::json::Value(std::move(object));
|
2020-07-13 18:26:41 -07:00
|
|
|
const char *uuid = module.GetUUIDString();
|
|
|
|
|
object.try_emplace("id", uuid ? std::string(uuid) : std::string(""));
|
2020-07-13 12:10:49 -07:00
|
|
|
object.try_emplace("name", std::string(module.GetFileSpec().GetFilename()));
|
|
|
|
|
char module_path_arr[PATH_MAX];
|
|
|
|
|
module.GetFileSpec().GetPath(module_path_arr, sizeof(module_path_arr));
|
|
|
|
|
std::string module_path(module_path_arr);
|
|
|
|
|
object.try_emplace("path", module_path);
|
|
|
|
|
if (module.GetNumCompileUnits() > 0) {
|
2020-07-24 13:30:04 -07:00
|
|
|
std::string symbol_str = "Symbols loaded.";
|
2020-09-01 15:59:51 -07:00
|
|
|
std::string debug_info_size;
|
2020-07-24 13:30:04 -07:00
|
|
|
uint64_t debug_info = GetDebugInfoSize(module);
|
|
|
|
|
if (debug_info > 0) {
|
2020-09-01 15:59:51 -07:00
|
|
|
debug_info_size = ConvertDebugInfoSizeToString(debug_info);
|
2020-07-24 13:30:04 -07:00
|
|
|
}
|
|
|
|
|
object.try_emplace("symbolStatus", symbol_str);
|
2020-09-01 15:59:51 -07:00
|
|
|
object.try_emplace("debugInfoSize", debug_info_size);
|
2020-07-13 12:10:49 -07:00
|
|
|
char symbol_path_arr[PATH_MAX];
|
2020-07-24 13:30:04 -07:00
|
|
|
module.GetSymbolFileSpec().GetPath(symbol_path_arr,
|
|
|
|
|
sizeof(symbol_path_arr));
|
2020-07-13 12:10:49 -07:00
|
|
|
std::string symbol_path(symbol_path_arr);
|
|
|
|
|
object.try_emplace("symbolFilePath", symbol_path);
|
|
|
|
|
} else {
|
|
|
|
|
object.try_emplace("symbolStatus", "Symbols not found.");
|
|
|
|
|
}
|
|
|
|
|
std::string loaded_addr = std::to_string(
|
2023-10-19 09:48:54 -07:00
|
|
|
module.GetObjectFileHeaderAddress().GetLoadAddress(g_dap.target));
|
2020-07-13 12:10:49 -07:00
|
|
|
object.try_emplace("addressRange", loaded_addr);
|
|
|
|
|
std::string version_str;
|
|
|
|
|
uint32_t version_nums[3];
|
2020-07-24 13:30:04 -07:00
|
|
|
uint32_t num_versions =
|
|
|
|
|
module.GetVersion(version_nums, sizeof(version_nums) / sizeof(uint32_t));
|
|
|
|
|
for (uint32_t i = 0; i < num_versions; ++i) {
|
2020-07-13 12:10:49 -07:00
|
|
|
if (!version_str.empty())
|
|
|
|
|
version_str += ".";
|
|
|
|
|
version_str += std::to_string(version_nums[i]);
|
|
|
|
|
}
|
|
|
|
|
if (!version_str.empty())
|
|
|
|
|
object.try_emplace("version", version_str);
|
|
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-13 11:38:02 -05:00
|
|
|
void AppendBreakpoint(BreakpointBase *bp, llvm::json::Array &breakpoints,
|
2023-01-07 14:18:35 -08:00
|
|
|
std::optional<llvm::StringRef> request_path,
|
|
|
|
|
std::optional<uint32_t> request_line) {
|
[lldb-vscode] Correctly return source mapped breakpoints for setBreakpoints request
Summary:
When using source maps for a breakpoint, in order to find the actual source that breakpoint has resolved, we
need to use a query similar to what CommandObjectSource::DumpLinesInSymbolContexts does, which is the logic
used by the CLI to display the source line at a given breakpoint. That's necessary because from a breakpoint
location you only have an address, which points to the original source location, not the source mapped one.
in the setBreakpoints request handler, we haven't been doing such query and we were returning the original
source location, which was breaking the UX of VSCode, as many breakpoints were being set but not displayed
in the source file next to each line. Besides, clicking the source path of a breakpoint in the breakpoints
view in the debug tab was not working for this case, as VSCode was trying to open a non-existent file, thus
showing an error to the user.
Ideally, we should do the query mentioned above to find the actual source location to respond to the IDE,
however, that query is expensive and users can have an arbitrary number of breakpoints set. As a simpler fix,
the request sent by VSCode already contains the full source path, which exists because the user set it from
the IDE itself, so we can simply reuse it instead of querying from the SB API.
I wrote a test for this, and found out that I had to move SetSourceMapFromArguments after RunInitCommands in
lldb-vscode.cpp, because an init command used in all tests is `settings clear -all`, which would clear the
source map unless specified after initCommands. And in any case, I think it makes sense to have initCommands
run before anything the debugger would do.
Reviewers: clayborg, kusmour, labath, aadsm
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D76968
2020-03-27 19:31:14 -07:00
|
|
|
breakpoints.emplace_back(CreateBreakpoint(bp, request_path, request_line));
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "Event": {
|
|
|
|
|
// "allOf": [ { "$ref": "#/definitions/ProtocolMessage" }, {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "Server-initiated event.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "type": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "enum": [ "event" ]
|
|
|
|
|
// },
|
|
|
|
|
// "event": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "Type of event."
|
|
|
|
|
// },
|
|
|
|
|
// "body": {
|
|
|
|
|
// "type": [ "array", "boolean", "integer", "null", "number" ,
|
|
|
|
|
// "object", "string" ],
|
|
|
|
|
// "description": "Event-specific information."
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "type", "event" ]
|
|
|
|
|
// }]
|
|
|
|
|
// },
|
|
|
|
|
// "ProtocolMessage": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "Base class of requests, responses, and events.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "seq": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "Sequence number."
|
|
|
|
|
// },
|
|
|
|
|
// "type": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "Message type.",
|
|
|
|
|
// "_enum": [ "request", "response", "event" ]
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "seq", "type" ]
|
|
|
|
|
// }
|
2018-08-16 18:24:59 +00:00
|
|
|
llvm::json::Object CreateEventObject(const llvm::StringRef event_name) {
|
2018-08-16 17:59:38 +00:00
|
|
|
llvm::json::Object event;
|
|
|
|
|
event.try_emplace("seq", 0);
|
|
|
|
|
event.try_emplace("type", "event");
|
2018-11-15 19:49:57 +00:00
|
|
|
EmplaceSafeString(event, "event", event_name);
|
2018-08-16 17:59:38 +00:00
|
|
|
return event;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "ExceptionBreakpointsFilter": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "An ExceptionBreakpointsFilter is shown in the UI as an
|
|
|
|
|
// option for configuring how exceptions are dealt with.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "filter": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The internal ID of the filter. This value is passed
|
|
|
|
|
// to the setExceptionBreakpoints request."
|
|
|
|
|
// },
|
|
|
|
|
// "label": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The name of the filter. This will be shown in the UI."
|
|
|
|
|
// },
|
|
|
|
|
// "default": {
|
|
|
|
|
// "type": "boolean",
|
|
|
|
|
// "description": "Initial value of the filter. If not specified a value
|
|
|
|
|
// 'false' is assumed."
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "filter", "label" ]
|
|
|
|
|
// }
|
|
|
|
|
llvm::json::Value
|
|
|
|
|
CreateExceptionBreakpointFilter(const ExceptionBreakpoint &bp) {
|
|
|
|
|
llvm::json::Object object;
|
2018-11-15 19:49:57 +00:00
|
|
|
EmplaceSafeString(object, "filter", bp.filter);
|
|
|
|
|
EmplaceSafeString(object, "label", bp.label);
|
2018-08-16 17:59:38 +00:00
|
|
|
object.try_emplace("default", bp.default_value);
|
|
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "Source": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "A Source is a descriptor for source code. It is returned
|
|
|
|
|
// from the debug adapter as part of a StackFrame and it is
|
|
|
|
|
// used by clients when specifying breakpoints.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "name": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The short name of the source. Every source returned
|
|
|
|
|
// from the debug adapter has a name. When sending a
|
|
|
|
|
// source to the debug adapter this name is optional."
|
|
|
|
|
// },
|
|
|
|
|
// "path": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The path of the source to be shown in the UI. It is
|
|
|
|
|
// only used to locate and load the content of the
|
|
|
|
|
// source if no sourceReference is specified (or its
|
|
|
|
|
// value is 0)."
|
|
|
|
|
// },
|
|
|
|
|
// "sourceReference": {
|
|
|
|
|
// "type": "number",
|
|
|
|
|
// "description": "If sourceReference > 0 the contents of the source must
|
|
|
|
|
// be retrieved through the SourceRequest (even if a path
|
|
|
|
|
// is specified). A sourceReference is only valid for a
|
|
|
|
|
// session, so it must not be used to persist a source."
|
|
|
|
|
// },
|
|
|
|
|
// "presentationHint": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "An optional hint for how to present the source in the
|
|
|
|
|
// UI. A value of 'deemphasize' can be used to indicate
|
|
|
|
|
// that the source is not available or that it is
|
|
|
|
|
// skipped on stepping.",
|
|
|
|
|
// "enum": [ "normal", "emphasize", "deemphasize" ]
|
|
|
|
|
// },
|
|
|
|
|
// "origin": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The (optional) origin of this source: possible values
|
|
|
|
|
// 'internal module', 'inlined content from source map',
|
|
|
|
|
// etc."
|
|
|
|
|
// },
|
|
|
|
|
// "sources": {
|
|
|
|
|
// "type": "array",
|
|
|
|
|
// "items": {
|
|
|
|
|
// "$ref": "#/definitions/Source"
|
|
|
|
|
// },
|
|
|
|
|
// "description": "An optional list of sources that are related to this
|
|
|
|
|
// source. These may be the source that generated this
|
|
|
|
|
// source."
|
|
|
|
|
// },
|
|
|
|
|
// "adapterData": {
|
|
|
|
|
// "type":["array","boolean","integer","null","number","object","string"],
|
|
|
|
|
// "description": "Optional data that a debug adapter might want to loop
|
|
|
|
|
// through the client. The client should leave the data
|
|
|
|
|
// intact and persist it across sessions. The client
|
|
|
|
|
// should not interpret the data."
|
|
|
|
|
// },
|
|
|
|
|
// "checksums": {
|
|
|
|
|
// "type": "array",
|
|
|
|
|
// "items": {
|
|
|
|
|
// "$ref": "#/definitions/Checksum"
|
|
|
|
|
// },
|
|
|
|
|
// "description": "The checksums associated with this file."
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-09-17 02:18:52 +02:00
|
|
|
llvm::json::Value CreateSource(const lldb::SBFileSpec &file) {
|
2018-08-16 17:59:38 +00:00
|
|
|
llvm::json::Object object;
|
|
|
|
|
if (file.IsValid()) {
|
|
|
|
|
const char *name = file.GetFilename();
|
|
|
|
|
if (name)
|
2018-11-15 19:49:57 +00:00
|
|
|
EmplaceSafeString(object, "name", name);
|
2018-08-16 17:59:38 +00:00
|
|
|
char path[PATH_MAX] = "";
|
2023-07-31 12:44:06 -04:00
|
|
|
if (file.GetPath(path, sizeof(path)) &&
|
|
|
|
|
lldb::SBFileSpec::ResolvePath(path, path, PATH_MAX)) {
|
2018-11-15 19:49:57 +00:00
|
|
|
EmplaceSafeString(object, "path", std::string(path));
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 02:18:52 +02:00
|
|
|
llvm::json::Value CreateSource(const lldb::SBLineEntry &line_entry) {
|
|
|
|
|
return CreateSource(line_entry.GetFileSpec());
|
|
|
|
|
}
|
|
|
|
|
|
[lldb-vscode] Correctly return source mapped breakpoints for setBreakpoints request
Summary:
When using source maps for a breakpoint, in order to find the actual source that breakpoint has resolved, we
need to use a query similar to what CommandObjectSource::DumpLinesInSymbolContexts does, which is the logic
used by the CLI to display the source line at a given breakpoint. That's necessary because from a breakpoint
location you only have an address, which points to the original source location, not the source mapped one.
in the setBreakpoints request handler, we haven't been doing such query and we were returning the original
source location, which was breaking the UX of VSCode, as many breakpoints were being set but not displayed
in the source file next to each line. Besides, clicking the source path of a breakpoint in the breakpoints
view in the debug tab was not working for this case, as VSCode was trying to open a non-existent file, thus
showing an error to the user.
Ideally, we should do the query mentioned above to find the actual source location to respond to the IDE,
however, that query is expensive and users can have an arbitrary number of breakpoints set. As a simpler fix,
the request sent by VSCode already contains the full source path, which exists because the user set it from
the IDE itself, so we can simply reuse it instead of querying from the SB API.
I wrote a test for this, and found out that I had to move SetSourceMapFromArguments after RunInitCommands in
lldb-vscode.cpp, because an init command used in all tests is `settings clear -all`, which would clear the
source map unless specified after initCommands. And in any case, I think it makes sense to have initCommands
run before anything the debugger would do.
Reviewers: clayborg, kusmour, labath, aadsm
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D76968
2020-03-27 19:31:14 -07:00
|
|
|
llvm::json::Value CreateSource(llvm::StringRef source_path) {
|
|
|
|
|
llvm::json::Object source;
|
|
|
|
|
llvm::StringRef name = llvm::sys::path::filename(source_path);
|
|
|
|
|
EmplaceSafeString(source, "name", name);
|
|
|
|
|
EmplaceSafeString(source, "path", source_path);
|
|
|
|
|
return llvm::json::Value(std::move(source));
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 12:44:06 -04:00
|
|
|
std::optional<llvm::json::Value> CreateSource(lldb::SBFrame &frame) {
|
2018-08-16 17:59:38 +00:00
|
|
|
auto line_entry = frame.GetLineEntry();
|
2023-06-29 14:53:52 -04:00
|
|
|
// A line entry of 0 indicates the line is compiler generated i.e. no source
|
2023-07-31 12:44:06 -04:00
|
|
|
// file is associated with the frame.
|
2023-06-29 14:53:52 -04:00
|
|
|
if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0)
|
2018-08-16 17:59:38 +00:00
|
|
|
return CreateSource(line_entry);
|
|
|
|
|
|
2023-07-31 12:44:06 -04:00
|
|
|
return {};
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "StackFrame": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "A Stackframe contains the source location.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "id": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "An identifier for the stack frame. It must be unique
|
|
|
|
|
// across all threads. This id can be used to retrieve
|
|
|
|
|
// the scopes of the frame with the 'scopesRequest' or
|
|
|
|
|
// to restart the execution of a stackframe."
|
|
|
|
|
// },
|
|
|
|
|
// "name": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The name of the stack frame, typically a method name."
|
|
|
|
|
// },
|
|
|
|
|
// "source": {
|
|
|
|
|
// "$ref": "#/definitions/Source",
|
|
|
|
|
// "description": "The optional source of the frame."
|
|
|
|
|
// },
|
|
|
|
|
// "line": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "The line within the file of the frame. If source is
|
|
|
|
|
// null or doesn't exist, line is 0 and must be ignored."
|
|
|
|
|
// },
|
|
|
|
|
// "column": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "The column within the line. If source is null or
|
|
|
|
|
// doesn't exist, column is 0 and must be ignored."
|
|
|
|
|
// },
|
|
|
|
|
// "endLine": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "An optional end line of the range covered by the
|
|
|
|
|
// stack frame."
|
|
|
|
|
// },
|
|
|
|
|
// "endColumn": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "An optional end column of the range covered by the
|
|
|
|
|
// stack frame."
|
|
|
|
|
// },
|
2023-07-31 12:44:06 -04:00
|
|
|
// "instructionPointerReference": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "A memory reference for the current instruction
|
2024-09-16 22:56:20 +02:00
|
|
|
// pointer in this frame."
|
2023-07-31 12:44:06 -04:00
|
|
|
// },
|
2018-08-16 17:59:38 +00:00
|
|
|
// "moduleId": {
|
|
|
|
|
// "type": ["integer", "string"],
|
|
|
|
|
// "description": "The module associated with this frame, if any."
|
|
|
|
|
// },
|
|
|
|
|
// "presentationHint": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "enum": [ "normal", "label", "subtle" ],
|
|
|
|
|
// "description": "An optional hint for how to present this frame in
|
|
|
|
|
// the UI. A value of 'label' can be used to indicate
|
|
|
|
|
// that the frame is an artificial frame that is used
|
|
|
|
|
// as a visual label or separator. A value of 'subtle'
|
|
|
|
|
// can be used to change the appearance of a frame in
|
|
|
|
|
// a 'subtle' way."
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "id", "name", "line", "column" ]
|
|
|
|
|
// }
|
|
|
|
|
llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) {
|
|
|
|
|
llvm::json::Object object;
|
2023-10-19 09:48:54 -07:00
|
|
|
int64_t frame_id = MakeDAPFrameID(frame);
|
2018-08-16 17:59:38 +00:00
|
|
|
object.try_emplace("id", frame_id);
|
2022-05-17 09:17:26 -07:00
|
|
|
|
2023-11-13 21:10:16 -05:00
|
|
|
std::string frame_name;
|
|
|
|
|
lldb::SBStream stream;
|
|
|
|
|
if (g_dap.frame_format &&
|
|
|
|
|
frame.GetDescriptionWithFormat(g_dap.frame_format, stream).Success()) {
|
|
|
|
|
frame_name = stream.GetData();
|
|
|
|
|
|
|
|
|
|
// `function_name` can be a nullptr, which throws an error when assigned to
|
|
|
|
|
// an `std::string`.
|
|
|
|
|
} else if (const char *name = frame.GetDisplayFunctionName()) {
|
|
|
|
|
frame_name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 10:36:09 -07:00
|
|
|
if (frame_name.empty()) {
|
|
|
|
|
// If the function name is unavailable, display the pc address as a 16-digit
|
|
|
|
|
// hex string, e.g. "0x0000000000012345"
|
|
|
|
|
llvm::raw_string_ostream os(frame_name);
|
|
|
|
|
os << llvm::format_hex(frame.GetPC(), 18);
|
|
|
|
|
}
|
2023-12-11 14:46:25 -05:00
|
|
|
|
|
|
|
|
// We only include `[opt]` if a custom frame format is not specified.
|
|
|
|
|
if (!g_dap.frame_format && frame.GetFunction().GetIsOptimized())
|
2022-05-17 09:17:26 -07:00
|
|
|
frame_name += " [opt]";
|
2023-12-11 14:46:25 -05:00
|
|
|
|
2022-05-17 09:17:26 -07:00
|
|
|
EmplaceSafeString(object, "name", frame_name);
|
|
|
|
|
|
2023-07-31 12:44:06 -04:00
|
|
|
auto source = CreateSource(frame);
|
2018-08-16 17:59:38 +00:00
|
|
|
|
2023-07-31 12:44:06 -04:00
|
|
|
if (source) {
|
|
|
|
|
object.try_emplace("source", *source);
|
|
|
|
|
auto line_entry = frame.GetLineEntry();
|
2018-08-16 17:59:38 +00:00
|
|
|
auto line = line_entry.GetLine();
|
2023-07-31 12:44:06 -04:00
|
|
|
if (line && line != LLDB_INVALID_LINE_NUMBER)
|
|
|
|
|
object.try_emplace("line", line);
|
2024-04-23 03:51:11 +08:00
|
|
|
else
|
|
|
|
|
object.try_emplace("line", 0);
|
2023-07-31 12:44:06 -04:00
|
|
|
auto column = line_entry.GetColumn();
|
2024-04-23 03:51:11 +08:00
|
|
|
object.try_emplace("column", column);
|
2023-07-31 12:44:06 -04:00
|
|
|
} else {
|
|
|
|
|
object.try_emplace("line", 0);
|
|
|
|
|
object.try_emplace("column", 0);
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
2023-07-31 12:44:06 -04:00
|
|
|
|
|
|
|
|
const auto pc = frame.GetPC();
|
|
|
|
|
if (pc != LLDB_INVALID_ADDRESS) {
|
|
|
|
|
std::string formatted_addr = "0x" + llvm::utohexstr(pc);
|
|
|
|
|
object.try_emplace("instructionPointerReference", formatted_addr);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-23 09:56:06 -07:00
|
|
|
if (frame.IsArtificial() || frame.IsHidden())
|
|
|
|
|
object.try_emplace("presentationHint", "subtle");
|
|
|
|
|
|
2018-08-16 17:59:38 +00:00
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-10 12:40:20 -07:00
|
|
|
llvm::json::Value CreateExtendedStackFrameLabel(lldb::SBThread &thread) {
|
|
|
|
|
std::string name;
|
|
|
|
|
lldb::SBStream stream;
|
|
|
|
|
if (g_dap.thread_format &&
|
|
|
|
|
thread.GetDescriptionWithFormat(g_dap.thread_format, stream).Success()) {
|
|
|
|
|
name = stream.GetData();
|
|
|
|
|
} else {
|
|
|
|
|
const uint32_t thread_idx = thread.GetExtendedBacktraceOriginatingIndexID();
|
|
|
|
|
const char *queue_name = thread.GetQueueName();
|
|
|
|
|
if (queue_name != nullptr) {
|
|
|
|
|
name = llvm::formatv("Enqueued from {0} (Thread {1})", queue_name,
|
|
|
|
|
thread_idx);
|
|
|
|
|
} else {
|
|
|
|
|
name = llvm::formatv("Thread {0}", thread_idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return llvm::json::Value(llvm::json::Object{{"id", thread.GetThreadID() + 1},
|
|
|
|
|
{"name", name},
|
|
|
|
|
{"presentationHint", "label"}});
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 00:19:39 +05:30
|
|
|
// Response to `setInstructionBreakpoints` request.
|
|
|
|
|
// "Breakpoint": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "Response to `setInstructionBreakpoints` request.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "id": {
|
|
|
|
|
// "type": "number",
|
|
|
|
|
// "description": "The identifier for the breakpoint. It is needed if
|
|
|
|
|
// breakpoint events are used to update or remove breakpoints."
|
|
|
|
|
// },
|
|
|
|
|
// "verified": {
|
|
|
|
|
// "type": "boolean",
|
|
|
|
|
// "description": "If true, the breakpoint could be set (but not
|
|
|
|
|
// necessarily at the desired location."
|
|
|
|
|
// },
|
|
|
|
|
// "message": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "A message about the state of the breakpoint.
|
|
|
|
|
// This is shown to the user and can be used to explain why a breakpoint
|
|
|
|
|
// could not be verified."
|
|
|
|
|
// },
|
|
|
|
|
// "source": {
|
|
|
|
|
// "type": "Source",
|
|
|
|
|
// "description": "The source where the breakpoint is located."
|
|
|
|
|
// },
|
|
|
|
|
// "line": {
|
|
|
|
|
// "type": "number",
|
|
|
|
|
// "description": "The start line of the actual range covered by the
|
|
|
|
|
// breakpoint."
|
|
|
|
|
// },
|
|
|
|
|
// "column": {
|
|
|
|
|
// "type": "number",
|
|
|
|
|
// "description": "The start column of the actual range covered by the
|
|
|
|
|
// breakpoint."
|
|
|
|
|
// },
|
|
|
|
|
// "endLine": {
|
|
|
|
|
// "type": "number",
|
|
|
|
|
// "description": "The end line of the actual range covered by the
|
|
|
|
|
// breakpoint."
|
|
|
|
|
// },
|
|
|
|
|
// "endColumn": {
|
|
|
|
|
// "type": "number",
|
|
|
|
|
// "description": "The end column of the actual range covered by the
|
|
|
|
|
// breakpoint. If no end line is given, then the end column is assumed to
|
|
|
|
|
// be in the start line."
|
|
|
|
|
// },
|
|
|
|
|
// "instructionReference": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "A memory reference to where the breakpoint is set."
|
|
|
|
|
// },
|
|
|
|
|
// "offset": {
|
|
|
|
|
// "type": "number",
|
|
|
|
|
// "description": "The offset from the instruction reference.
|
|
|
|
|
// This can be negative."
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "id", "verified", "line"]
|
|
|
|
|
// }
|
|
|
|
|
llvm::json::Value CreateInstructionBreakpoint(BreakpointBase *ibp) {
|
|
|
|
|
llvm::json::Object object;
|
|
|
|
|
ibp->CreateJsonObject(object);
|
|
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 17:59:38 +00:00
|
|
|
// "Thread": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "A Thread",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "id": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "Unique identifier for the thread."
|
|
|
|
|
// },
|
|
|
|
|
// "name": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "A name of the thread."
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "id", "name" ]
|
|
|
|
|
// }
|
|
|
|
|
llvm::json::Value CreateThread(lldb::SBThread &thread) {
|
|
|
|
|
llvm::json::Object object;
|
|
|
|
|
object.try_emplace("id", (int64_t)thread.GetThreadID());
|
2023-07-28 14:22:19 -04:00
|
|
|
std::string thread_str;
|
2023-11-14 13:23:55 -05:00
|
|
|
lldb::SBStream stream;
|
|
|
|
|
if (g_dap.thread_format &&
|
|
|
|
|
thread.GetDescriptionWithFormat(g_dap.thread_format, stream).Success()) {
|
|
|
|
|
thread_str = stream.GetData();
|
2018-08-16 17:59:38 +00:00
|
|
|
} else {
|
2023-11-14 13:23:55 -05:00
|
|
|
const char *thread_name = thread.GetName();
|
|
|
|
|
const char *queue_name = thread.GetQueueName();
|
|
|
|
|
|
|
|
|
|
if (thread_name) {
|
|
|
|
|
thread_str = std::string(thread_name);
|
|
|
|
|
} else if (queue_name) {
|
|
|
|
|
auto kind = thread.GetQueue().GetKind();
|
|
|
|
|
std::string queue_kind_label = "";
|
|
|
|
|
if (kind == lldb::eQueueKindSerial) {
|
|
|
|
|
queue_kind_label = " (serial)";
|
|
|
|
|
} else if (kind == lldb::eQueueKindConcurrent) {
|
|
|
|
|
queue_kind_label = " (concurrent)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
thread_str =
|
|
|
|
|
llvm::formatv("Thread {0} Queue: {1}{2}", thread.GetIndexID(),
|
|
|
|
|
queue_name, queue_kind_label)
|
|
|
|
|
.str();
|
|
|
|
|
} else {
|
|
|
|
|
thread_str = llvm::formatv("Thread {0}", thread.GetIndexID()).str();
|
|
|
|
|
}
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
2023-07-28 14:22:19 -04:00
|
|
|
|
|
|
|
|
EmplaceSafeString(object, "name", thread_str);
|
|
|
|
|
|
2018-08-16 17:59:38 +00:00
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "StoppedEvent": {
|
|
|
|
|
// "allOf": [ { "$ref": "#/definitions/Event" }, {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "Event message for 'stopped' event type. The event
|
|
|
|
|
// indicates that the execution of the debuggee has stopped
|
|
|
|
|
// due to some condition. This can be caused by a break
|
|
|
|
|
// point previously set, a stepping action has completed,
|
|
|
|
|
// by executing a debugger statement etc.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "event": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "enum": [ "stopped" ]
|
|
|
|
|
// },
|
|
|
|
|
// "body": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "reason": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The reason for the event. For backward
|
|
|
|
|
// compatibility this string is shown in the UI if
|
|
|
|
|
// the 'description' attribute is missing (but it
|
|
|
|
|
// must not be translated).",
|
|
|
|
|
// "_enum": [ "step", "breakpoint", "exception", "pause", "entry" ]
|
|
|
|
|
// },
|
|
|
|
|
// "description": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The full reason for the event, e.g. 'Paused
|
|
|
|
|
// on exception'. This string is shown in the UI
|
|
|
|
|
// as is."
|
|
|
|
|
// },
|
|
|
|
|
// "threadId": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "The thread which was stopped."
|
|
|
|
|
// },
|
|
|
|
|
// "text": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "Additional information. E.g. if reason is
|
|
|
|
|
// 'exception', text contains the exception name.
|
|
|
|
|
// This string is shown in the UI."
|
|
|
|
|
// },
|
|
|
|
|
// "allThreadsStopped": {
|
|
|
|
|
// "type": "boolean",
|
|
|
|
|
// "description": "If allThreadsStopped is true, a debug adapter
|
|
|
|
|
// can announce that all threads have stopped.
|
|
|
|
|
// The client should use this information to
|
|
|
|
|
// enable that all threads can be expanded to
|
|
|
|
|
// access their stacktraces. If the attribute
|
|
|
|
|
// is missing or false, only the thread with the
|
|
|
|
|
// given threadId can be expanded."
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "reason" ]
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// "required": [ "event", "body" ]
|
|
|
|
|
// }]
|
|
|
|
|
// }
|
|
|
|
|
llvm::json::Value CreateThreadStopped(lldb::SBThread &thread,
|
|
|
|
|
uint32_t stop_id) {
|
2018-08-16 18:24:59 +00:00
|
|
|
llvm::json::Object event(CreateEventObject("stopped"));
|
2018-08-16 17:59:38 +00:00
|
|
|
llvm::json::Object body;
|
|
|
|
|
switch (thread.GetStopReason()) {
|
|
|
|
|
case lldb::eStopReasonTrace:
|
|
|
|
|
case lldb::eStopReasonPlanComplete:
|
|
|
|
|
body.try_emplace("reason", "step");
|
|
|
|
|
break;
|
|
|
|
|
case lldb::eStopReasonBreakpoint: {
|
2023-10-19 09:48:54 -07:00
|
|
|
ExceptionBreakpoint *exc_bp = g_dap.GetExceptionBPFromStopReason(thread);
|
2018-08-16 17:59:38 +00:00
|
|
|
if (exc_bp) {
|
|
|
|
|
body.try_emplace("reason", "exception");
|
2018-11-15 19:49:57 +00:00
|
|
|
EmplaceSafeString(body, "description", exc_bp->label);
|
2018-08-16 17:59:38 +00:00
|
|
|
} else {
|
2024-08-27 00:19:39 +05:30
|
|
|
InstructionBreakpoint *inst_bp =
|
|
|
|
|
g_dap.GetInstructionBPFromStopReason(thread);
|
|
|
|
|
if (inst_bp) {
|
|
|
|
|
body.try_emplace("reason", "instruction breakpoint");
|
|
|
|
|
} else {
|
|
|
|
|
body.try_emplace("reason", "breakpoint");
|
|
|
|
|
}
|
2023-11-30 12:17:12 -08:00
|
|
|
lldb::break_id_t bp_id = thread.GetStopReasonDataAtIndex(0);
|
|
|
|
|
lldb::break_id_t bp_loc_id = thread.GetStopReasonDataAtIndex(1);
|
|
|
|
|
std::string desc_str =
|
|
|
|
|
llvm::formatv("breakpoint {0}.{1}", bp_id, bp_loc_id);
|
2023-07-25 14:15:15 -04:00
|
|
|
body.try_emplace("hitBreakpointIds",
|
|
|
|
|
llvm::json::Array{llvm::json::Value(bp_id)});
|
2020-01-29 14:11:40 -08:00
|
|
|
EmplaceSafeString(body, "description", desc_str);
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
case lldb::eStopReasonWatchpoint:
|
|
|
|
|
case lldb::eStopReasonInstrumentation:
|
|
|
|
|
body.try_emplace("reason", "breakpoint");
|
|
|
|
|
break;
|
2020-11-09 13:36:26 -08:00
|
|
|
case lldb::eStopReasonProcessorTrace:
|
|
|
|
|
body.try_emplace("reason", "processor trace");
|
2018-08-16 17:59:38 +00:00
|
|
|
break;
|
2020-11-09 13:36:26 -08:00
|
|
|
case lldb::eStopReasonSignal:
|
2018-08-16 17:59:38 +00:00
|
|
|
case lldb::eStopReasonException:
|
|
|
|
|
body.try_emplace("reason", "exception");
|
|
|
|
|
break;
|
|
|
|
|
case lldb::eStopReasonExec:
|
|
|
|
|
body.try_emplace("reason", "entry");
|
|
|
|
|
break;
|
2021-03-29 17:05:30 +02:00
|
|
|
case lldb::eStopReasonFork:
|
|
|
|
|
body.try_emplace("reason", "fork");
|
|
|
|
|
break;
|
|
|
|
|
case lldb::eStopReasonVFork:
|
|
|
|
|
body.try_emplace("reason", "vfork");
|
|
|
|
|
break;
|
|
|
|
|
case lldb::eStopReasonVForkDone:
|
|
|
|
|
body.try_emplace("reason", "vforkdone");
|
|
|
|
|
break;
|
New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (#90930)
This PR introduces a new `ThreadPlanSingleThreadTimeout` that will be
used to address potential deadlock during single-thread stepping.
While debugging a target with a non-trivial number of threads (around
5000 threads in one example target), we noticed that a simple step over
can take as long as 10 seconds. Enabling single-thread stepping mode
significantly reduces the stepping time to around 3 seconds. However,
this can introduce deadlock if we try to step over a method that depends
on other threads to release a lock.
To address this issue, we introduce a new
`ThreadPlanSingleThreadTimeout` that can be controlled by the
`target.process.thread.single-thread-plan-timeout` setting during
single-thread stepping mode. The concept involves counting the elapsed
time since the last internal stop to detect overall stepping progress.
Once a timeout occurs, we assume the target is not making progress due
to a potential deadlock, as mentioned above. We then send a new async
interrupt, resume all threads, and `ThreadPlanSingleThreadTimeout`
completes its task.
To support this design, the major changes made in this PR are:
1. `ThreadPlanSingleThreadTimeout` is popped during every internal stop
and reset (re-pushed) to the top of the stack (as a leaf node) during
resume. This is achieved by always returning `true` from
`ThreadPlanSingleThreadTimeout::DoPlanExplainsStop()` and
`ThreadPlanSingleThreadTimeout::MischiefManaged()`.
2. A new thread-specific async interrupt stop is introduced, which can
be detected/consumed by `ThreadPlanSingleThreadTimeout`.
3. The clearing of branch breakpoints in the range thread plan has been
moved from `DoPlanExplainsStop()` to `ShouldStop()`, as it is not
guaranteed that it will be called.
The detailed design is discussed in the RFC below:
[https://discourse.llvm.org/t/improve-single-thread-stepping/74599](https://discourse.llvm.org/t/improve-single-thread-stepping/74599)
---------
Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2024-08-05 17:26:39 -07:00
|
|
|
case lldb::eStopReasonInterrupt:
|
|
|
|
|
body.try_emplace("reason", "async interrupt");
|
|
|
|
|
break;
|
2018-08-16 17:59:38 +00:00
|
|
|
case lldb::eStopReasonThreadExiting:
|
|
|
|
|
case lldb::eStopReasonInvalid:
|
|
|
|
|
case lldb::eStopReasonNone:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (stop_id == 0)
|
|
|
|
|
body.try_emplace("reason", "entry");
|
|
|
|
|
const lldb::tid_t tid = thread.GetThreadID();
|
|
|
|
|
body.try_emplace("threadId", (int64_t)tid);
|
|
|
|
|
// If no description has been set, then set it to the default thread stopped
|
|
|
|
|
// description. If we have breakpoints that get hit and shouldn't be reported
|
|
|
|
|
// as breakpoints, then they will set the description above.
|
2022-10-19 11:58:23 -07:00
|
|
|
if (!ObjectContainsKey(body, "description")) {
|
2018-08-16 17:59:38 +00:00
|
|
|
char description[1024];
|
|
|
|
|
if (thread.GetStopDescription(description, sizeof(description))) {
|
2018-11-15 19:49:57 +00:00
|
|
|
EmplaceSafeString(body, "description", std::string(description));
|
2018-08-16 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-25 14:15:15 -04:00
|
|
|
// "threadCausedFocus" is used in tests to validate breaking behavior.
|
2023-10-19 09:48:54 -07:00
|
|
|
if (tid == g_dap.focus_tid) {
|
2018-08-16 17:59:38 +00:00
|
|
|
body.try_emplace("threadCausedFocus", true);
|
|
|
|
|
}
|
2023-10-19 09:48:54 -07:00
|
|
|
body.try_emplace("preserveFocusHint", tid != g_dap.focus_tid);
|
2018-08-16 17:59:38 +00:00
|
|
|
body.try_emplace("allThreadsStopped", true);
|
|
|
|
|
event.try_emplace("body", std::move(body));
|
|
|
|
|
return llvm::json::Value(std::move(event));
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 16:02:38 -07:00
|
|
|
const char *GetNonNullVariableName(lldb::SBValue v) {
|
|
|
|
|
const char *name = v.GetName();
|
|
|
|
|
return name ? name : "<null>";
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-21 15:06:44 -07:00
|
|
|
std::string CreateUniqueVariableNameForDisplay(lldb::SBValue v,
|
|
|
|
|
bool is_name_duplicated) {
|
|
|
|
|
lldb::SBStream name_builder;
|
2021-04-27 16:02:38 -07:00
|
|
|
name_builder.Print(GetNonNullVariableName(v));
|
2021-04-21 15:06:44 -07:00
|
|
|
if (is_name_duplicated) {
|
|
|
|
|
lldb::SBDeclaration declaration = v.GetDeclaration();
|
2021-04-27 16:02:38 -07:00
|
|
|
const char *file_name = declaration.GetFileSpec().GetFilename();
|
2021-04-21 15:06:44 -07:00
|
|
|
const uint32_t line = declaration.GetLine();
|
|
|
|
|
|
2021-04-27 16:02:38 -07:00
|
|
|
if (file_name != nullptr && line > 0)
|
|
|
|
|
name_builder.Printf(" @ %s:%u", file_name, line);
|
|
|
|
|
else if (const char *location = v.GetLocation())
|
|
|
|
|
name_builder.Printf(" @ %s", location);
|
2021-04-21 15:06:44 -07:00
|
|
|
}
|
|
|
|
|
return name_builder.GetData();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-02 13:06:13 -05:00
|
|
|
VariableDescription::VariableDescription(lldb::SBValue v, bool format_hex,
|
|
|
|
|
bool is_name_duplicated,
|
|
|
|
|
std::optional<std::string> custom_name)
|
|
|
|
|
: v(v) {
|
|
|
|
|
name = custom_name
|
|
|
|
|
? *custom_name
|
|
|
|
|
: CreateUniqueVariableNameForDisplay(v, is_name_duplicated);
|
|
|
|
|
|
|
|
|
|
type_obj = v.GetType();
|
|
|
|
|
std::string raw_display_type_name =
|
|
|
|
|
llvm::StringRef(type_obj.GetDisplayTypeName()).str();
|
|
|
|
|
display_type_name =
|
|
|
|
|
!raw_display_type_name.empty() ? raw_display_type_name : NO_TYPENAME;
|
|
|
|
|
|
2024-05-03 13:36:23 -07:00
|
|
|
// Only format hex/default if there is no existing special format.
|
|
|
|
|
if (v.GetFormat() == lldb::eFormatDefault ||
|
|
|
|
|
v.GetFormat() == lldb::eFormatHex) {
|
|
|
|
|
if (format_hex)
|
|
|
|
|
v.SetFormat(lldb::eFormatHex);
|
|
|
|
|
else
|
|
|
|
|
v.SetFormat(lldb::eFormatDefault);
|
|
|
|
|
}
|
2024-01-02 13:06:13 -05:00
|
|
|
|
|
|
|
|
llvm::raw_string_ostream os_display_value(display_value);
|
|
|
|
|
|
|
|
|
|
if (lldb::SBError sb_error = v.GetError(); sb_error.Fail()) {
|
|
|
|
|
error = sb_error.GetCString();
|
|
|
|
|
os_display_value << "<error: " << error << ">";
|
|
|
|
|
} else {
|
|
|
|
|
value = llvm::StringRef(v.GetValue()).str();
|
|
|
|
|
summary = llvm::StringRef(v.GetSummary()).str();
|
|
|
|
|
if (summary.empty())
|
|
|
|
|
auto_summary = TryCreateAutoSummary(v);
|
|
|
|
|
|
|
|
|
|
std::optional<std::string> effective_summary =
|
|
|
|
|
!summary.empty() ? summary : auto_summary;
|
|
|
|
|
|
|
|
|
|
if (!value.empty()) {
|
|
|
|
|
os_display_value << value;
|
|
|
|
|
if (effective_summary)
|
|
|
|
|
os_display_value << " " << *effective_summary;
|
|
|
|
|
} else if (effective_summary) {
|
|
|
|
|
os_display_value << *effective_summary;
|
|
|
|
|
|
|
|
|
|
// As last resort, we print its type and address if available.
|
|
|
|
|
} else {
|
|
|
|
|
if (!raw_display_type_name.empty()) {
|
|
|
|
|
os_display_value << raw_display_type_name;
|
|
|
|
|
lldb::addr_t address = v.GetLoadAddress();
|
|
|
|
|
if (address != LLDB_INVALID_ADDRESS)
|
|
|
|
|
os_display_value << " @ " << llvm::format_hex(address, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lldb::SBStream evaluateStream;
|
|
|
|
|
v.GetExpressionPath(evaluateStream);
|
|
|
|
|
evaluate_name = llvm::StringRef(evaluateStream.GetData()).str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llvm::json::Object VariableDescription::GetVariableExtensionsJSON() {
|
|
|
|
|
llvm::json::Object extensions;
|
|
|
|
|
if (error)
|
|
|
|
|
EmplaceSafeString(extensions, "error", *error);
|
|
|
|
|
if (!value.empty())
|
|
|
|
|
EmplaceSafeString(extensions, "value", value);
|
|
|
|
|
if (!summary.empty())
|
|
|
|
|
EmplaceSafeString(extensions, "summary", summary);
|
|
|
|
|
if (auto_summary)
|
|
|
|
|
EmplaceSafeString(extensions, "autoSummary", *auto_summary);
|
|
|
|
|
|
|
|
|
|
if (lldb::SBDeclaration decl = v.GetDeclaration(); decl.IsValid()) {
|
|
|
|
|
llvm::json::Object decl_obj;
|
|
|
|
|
if (lldb::SBFileSpec file = decl.GetFileSpec(); file.IsValid()) {
|
|
|
|
|
char path[PATH_MAX] = "";
|
|
|
|
|
if (file.GetPath(path, sizeof(path)) &&
|
|
|
|
|
lldb::SBFileSpec::ResolvePath(path, path, PATH_MAX)) {
|
|
|
|
|
decl_obj.try_emplace("path", std::string(path));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (int line = decl.GetLine())
|
|
|
|
|
decl_obj.try_emplace("line", line);
|
|
|
|
|
if (int column = decl.GetColumn())
|
|
|
|
|
decl_obj.try_emplace("column", column);
|
|
|
|
|
|
|
|
|
|
if (!decl_obj.empty())
|
|
|
|
|
extensions.try_emplace("declaration", std::move(decl_obj));
|
|
|
|
|
}
|
|
|
|
|
return extensions;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 14:12:30 -08:00
|
|
|
std::string VariableDescription::GetResult(llvm::StringRef context) {
|
2024-05-21 10:37:41 +02:00
|
|
|
// In repl context, the results can be displayed as multiple lines so more
|
|
|
|
|
// detailed descriptions can be returned.
|
|
|
|
|
if (context != "repl")
|
2024-01-12 14:12:30 -08:00
|
|
|
return display_value;
|
|
|
|
|
|
|
|
|
|
if (!v.IsValid())
|
|
|
|
|
return display_value;
|
|
|
|
|
|
|
|
|
|
// Try the SBValue::GetDescription(), which may call into language runtime
|
|
|
|
|
// specific formatters (see ValueObjectPrinter).
|
|
|
|
|
lldb::SBStream stream;
|
|
|
|
|
v.GetDescription(stream);
|
|
|
|
|
llvm::StringRef description = stream.GetData();
|
|
|
|
|
return description.trim().str();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 17:59:38 +00:00
|
|
|
// "Variable": {
|
|
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "A Variable is a name/value pair. Optionally a variable
|
|
|
|
|
// can have a 'type' that is shown if space permits or when
|
|
|
|
|
// hovering over the variable's name. An optional 'kind' is
|
|
|
|
|
// used to render additional properties of the variable,
|
|
|
|
|
// e.g. different icons can be used to indicate that a
|
|
|
|
|
// variable is public or private. If the value is
|
|
|
|
|
// structured (has children), a handle is provided to
|
|
|
|
|
// retrieve the children with the VariablesRequest. If
|
|
|
|
|
// the number of named or indexed children is large, the
|
|
|
|
|
// numbers should be returned via the optional
|
|
|
|
|
// 'namedVariables' and 'indexedVariables' attributes. The
|
|
|
|
|
// client can use this optional information to present the
|
|
|
|
|
// children in a paged UI and fetch them in chunks.",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "name": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The variable's name."
|
|
|
|
|
// },
|
|
|
|
|
// "value": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The variable's value. This can be a multi-line text,
|
|
|
|
|
// e.g. for a function the body of a function."
|
|
|
|
|
// },
|
|
|
|
|
// "type": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The type of the variable's value. Typically shown in
|
|
|
|
|
// the UI when hovering over the value."
|
|
|
|
|
// },
|
|
|
|
|
// "presentationHint": {
|
|
|
|
|
// "$ref": "#/definitions/VariablePresentationHint",
|
|
|
|
|
// "description": "Properties of a variable that can be used to determine
|
|
|
|
|
// how to render the variable in the UI."
|
|
|
|
|
// },
|
|
|
|
|
// "evaluateName": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "Optional evaluatable name of this variable which can
|
|
|
|
|
// be passed to the 'EvaluateRequest' to fetch the
|
|
|
|
|
// variable's value."
|
|
|
|
|
// },
|
|
|
|
|
// "variablesReference": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "If variablesReference is > 0, the variable is
|
|
|
|
|
// structured and its children can be retrieved by
|
|
|
|
|
// passing variablesReference to the VariablesRequest."
|
|
|
|
|
// },
|
|
|
|
|
// "namedVariables": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "The number of named child variables. The client can
|
|
|
|
|
// use this optional information to present the children
|
|
|
|
|
// in a paged UI and fetch them in chunks."
|
|
|
|
|
// },
|
|
|
|
|
// "indexedVariables": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "The number of indexed child variables. The client
|
|
|
|
|
// can use this optional information to present the
|
|
|
|
|
// children in a paged UI and fetch them in chunks."
|
2024-09-17 02:18:52 +02:00
|
|
|
// },
|
2024-09-16 22:56:20 +02:00
|
|
|
// "memoryReference": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "A memory reference associated with this variable.
|
|
|
|
|
// For pointer type variables, this is generally a
|
|
|
|
|
// reference to the memory address contained in the
|
|
|
|
|
// pointer. For executable data, this reference may later
|
|
|
|
|
// be used in a `disassemble` request. This attribute may
|
|
|
|
|
// be returned by a debug adapter if corresponding
|
|
|
|
|
// capability `supportsMemoryReferences` is true."
|
2024-09-17 02:18:52 +02:00
|
|
|
// },
|
|
|
|
|
// "declarationLocationReference": {
|
|
|
|
|
// "type": "integer",
|
|
|
|
|
// "description": "A reference that allows the client to request the
|
|
|
|
|
// location where the variable is declared. This should be
|
|
|
|
|
// present only if the adapter is likely to be able to
|
|
|
|
|
// resolve the location.\n\nThis reference shares the same
|
|
|
|
|
// lifetime as the `variablesReference`. See 'Lifetime of
|
|
|
|
|
// Object References' in the Overview section for
|
|
|
|
|
// details."
|
|
|
|
|
// },
|
|
|
|
|
//
|
2024-01-02 13:06:13 -05:00
|
|
|
// "$__lldb_extensions": {
|
|
|
|
|
// "description": "Unofficial extensions to the protocol",
|
2023-12-11 15:20:06 -05:00
|
|
|
// "properties": {
|
2024-01-02 13:06:13 -05:00
|
|
|
// "declaration": {
|
2024-09-17 02:18:52 +02:00
|
|
|
// "type": "object",
|
|
|
|
|
// "description": "The source location where the variable was
|
|
|
|
|
// declared. This value won't be present if no
|
|
|
|
|
// declaration is available.
|
|
|
|
|
// Superseded by `declarationLocationReference`",
|
|
|
|
|
// "properties": {
|
|
|
|
|
// "path": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The source file path where the variable was
|
|
|
|
|
// declared."
|
|
|
|
|
// },
|
|
|
|
|
// "line": {
|
|
|
|
|
// "type": "number",
|
|
|
|
|
// "description": "The 1-indexed source line where the variable
|
|
|
|
|
// was declared."
|
|
|
|
|
// },
|
|
|
|
|
// "column": {
|
|
|
|
|
// "type": "number",
|
|
|
|
|
// "description": "The 1-indexed source column where the variable
|
|
|
|
|
// was declared."
|
|
|
|
|
// }
|
2024-01-02 13:06:13 -05:00
|
|
|
// }
|
2024-09-17 02:18:52 +02:00
|
|
|
// },
|
|
|
|
|
// "value": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The internal value of the variable as returned by
|
|
|
|
|
// This is effectively SBValue.GetValue(). The other
|
|
|
|
|
// `value` entry in the top-level variable response
|
|
|
|
|
// is, on the other hand, just a display string for
|
|
|
|
|
// the variable."
|
|
|
|
|
// },
|
|
|
|
|
// "summary": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The summary string of the variable. This is
|
|
|
|
|
// effectively SBValue.GetSummary()."
|
|
|
|
|
// },
|
|
|
|
|
// "autoSummary": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "The auto generated summary if using
|
|
|
|
|
// `enableAutoVariableSummaries`."
|
|
|
|
|
// },
|
|
|
|
|
// "error": {
|
|
|
|
|
// "type": "string",
|
|
|
|
|
// "description": "An error message generated if LLDB couldn't inspect
|
|
|
|
|
// the variable."
|
2023-12-11 15:20:06 -05:00
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2018-08-16 17:59:38 +00:00
|
|
|
// },
|
|
|
|
|
// "required": [ "name", "value", "variablesReference" ]
|
|
|
|
|
// }
|
2024-09-17 02:18:52 +02:00
|
|
|
llvm::json::Value CreateVariable(lldb::SBValue v, int64_t var_ref,
|
|
|
|
|
bool format_hex, bool is_name_duplicated,
|
2023-09-06 20:13:48 -04:00
|
|
|
std::optional<std::string> custom_name) {
|
2024-01-02 13:06:13 -05:00
|
|
|
VariableDescription desc(v, format_hex, is_name_duplicated, custom_name);
|
2018-08-16 17:59:38 +00:00
|
|
|
llvm::json::Object object;
|
2024-01-02 13:06:13 -05:00
|
|
|
EmplaceSafeString(object, "name", desc.name);
|
|
|
|
|
EmplaceSafeString(object, "value", desc.display_value);
|
|
|
|
|
|
|
|
|
|
if (!desc.evaluate_name.empty())
|
|
|
|
|
EmplaceSafeString(object, "evaluateName", desc.evaluate_name);
|
2021-04-21 15:06:44 -07:00
|
|
|
|
2023-09-01 21:32:24 -07:00
|
|
|
// If we have a type with many children, we would like to be able to
|
Add "indexedVariables" to variables with lots of children.
Prior to this fix if we have a really large array or collection class, we would end up always creating all of the child variables for an array or collection class. If the number of children was very high this can cause delays when expanding variables. By adding the "indexedVariables" to variables with lots of children, we can keep good performance in the variables view at all times. This patch will add the "indexedVariables" key/value pair to any "Variable" JSON dictionairies when we have an array of synthetic child provider that will create more than 100 children.
We have to be careful to not call "uint32_t SBValue::GetNumChildren()" on any lldb::SBValue that we use because it can cause a class, struct or union to complete the type in order to be able to properly tell us how many children it has and this can be expensive if you have a lot of variables. By default LLDB won't need to complete a type if we have variables that are classes, structs or unions unless the user expands the variable in the variable view. So we try to only get the GetNumChildren() when we have an array, as this is a cheap operation, or a synthetic child provider, most of which are for showing collections that typically fall into this category. We add a variable reference, which indicates that something can be expanded, when the function "bool SBValue::MightHaveChildren()" is true as this call doesn't need to complete the type in order to return true. This way if no one ever expands class variables, we don't need to complete the type.
Differential Revision: https://reviews.llvm.org/D125347
2022-05-10 13:41:06 -07:00
|
|
|
// give a hint to the IDE that the type has indexed children so that the
|
2024-01-02 13:06:13 -05:00
|
|
|
// request can be broken up in grabbing only a few children at a time. We
|
|
|
|
|
// want to be careful and only call "v.GetNumChildren()" if we have an array
|
2024-05-30 09:54:13 +02:00
|
|
|
// type or if we have a synthetic child provider producing indexed children.
|
|
|
|
|
// We don't want to call "v.GetNumChildren()" on all objects as class, struct
|
|
|
|
|
// and union types don't need to be completed if they are never expanded. So
|
|
|
|
|
// we want to avoid calling this to only cases where we it makes sense to keep
|
2024-01-02 13:06:13 -05:00
|
|
|
// performance high during normal debugging.
|
|
|
|
|
|
|
|
|
|
// If we have an array type, say that it is indexed and provide the number
|
|
|
|
|
// of children in case we have a huge array. If we don't do this, then we
|
|
|
|
|
// might take a while to produce all children at onces which can delay your
|
|
|
|
|
// debug session.
|
2024-05-30 09:54:13 +02:00
|
|
|
if (desc.type_obj.IsArrayType()) {
|
|
|
|
|
object.try_emplace("indexedVariables", v.GetNumChildren());
|
|
|
|
|
} else if (v.IsSynthetic()) {
|
|
|
|
|
// For a type with a synthetic child provider, the SBType of "v" won't tell
|
|
|
|
|
// us anything about what might be displayed. Instead, we check if the first
|
|
|
|
|
// child's name is "[0]" and then say it is indexed. We call
|
|
|
|
|
// GetNumChildren() only if the child name matches to avoid a potentially
|
|
|
|
|
// expensive operation.
|
|
|
|
|
if (lldb::SBValue first_child = v.GetChildAtIndex(0)) {
|
|
|
|
|
llvm::StringRef first_child_name = first_child.GetName();
|
|
|
|
|
if (first_child_name == "[0]") {
|
|
|
|
|
size_t num_children = v.GetNumChildren();
|
|
|
|
|
// If we are creating a "[raw]" fake child for each synthetic type, we
|
|
|
|
|
// have to account for it when returning indexed variables.
|
|
|
|
|
if (g_dap.enable_synthetic_child_debugging)
|
|
|
|
|
++num_children;
|
|
|
|
|
object.try_emplace("indexedVariables", num_children);
|
|
|
|
|
}
|
Add "indexedVariables" to variables with lots of children.
Prior to this fix if we have a really large array or collection class, we would end up always creating all of the child variables for an array or collection class. If the number of children was very high this can cause delays when expanding variables. By adding the "indexedVariables" to variables with lots of children, we can keep good performance in the variables view at all times. This patch will add the "indexedVariables" key/value pair to any "Variable" JSON dictionairies when we have an array of synthetic child provider that will create more than 100 children.
We have to be careful to not call "uint32_t SBValue::GetNumChildren()" on any lldb::SBValue that we use because it can cause a class, struct or union to complete the type in order to be able to properly tell us how many children it has and this can be expensive if you have a lot of variables. By default LLDB won't need to complete a type if we have variables that are classes, structs or unions unless the user expands the variable in the variable view. So we try to only get the GetNumChildren() when we have an array, as this is a cheap operation, or a synthetic child provider, most of which are for showing collections that typically fall into this category. We add a variable reference, which indicates that something can be expanded, when the function "bool SBValue::MightHaveChildren()" is true as this call doesn't need to complete the type in order to return true. This way if no one ever expands class variables, we don't need to complete the type.
Differential Revision: https://reviews.llvm.org/D125347
2022-05-10 13:41:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
2024-01-02 13:06:13 -05:00
|
|
|
EmplaceSafeString(object, "type", desc.display_type_name);
|
2024-09-17 02:18:52 +02:00
|
|
|
|
|
|
|
|
// A unique variable identifier to help in properly identifying variables with
|
|
|
|
|
// the same name. This is an extension to the VS protocol.
|
|
|
|
|
object.try_emplace("id", var_ref);
|
|
|
|
|
|
2018-08-16 17:59:38 +00:00
|
|
|
if (v.MightHaveChildren())
|
2024-09-17 02:18:52 +02:00
|
|
|
object.try_emplace("variablesReference", var_ref);
|
2018-08-16 17:59:38 +00:00
|
|
|
else
|
2024-09-17 02:18:52 +02:00
|
|
|
object.try_emplace("variablesReference", 0);
|
|
|
|
|
|
|
|
|
|
if (v.GetDeclaration().IsValid())
|
|
|
|
|
object.try_emplace("declarationLocationReference", var_ref);
|
2023-12-11 15:20:06 -05:00
|
|
|
|
2024-09-16 22:56:20 +02:00
|
|
|
if (lldb::addr_t addr = v.GetLoadAddress(); addr != LLDB_INVALID_ADDRESS)
|
|
|
|
|
object.try_emplace("memoryReference", EncodeMemoryReference(addr));
|
|
|
|
|
|
2024-01-02 13:06:13 -05:00
|
|
|
object.try_emplace("$__lldb_extensions", desc.GetVariableExtensionsJSON());
|
2018-08-16 17:59:38 +00:00
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 12:10:49 -07:00
|
|
|
llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit unit) {
|
|
|
|
|
llvm::json::Object object;
|
|
|
|
|
char unit_path_arr[PATH_MAX];
|
|
|
|
|
unit.GetFileSpec().GetPath(unit_path_arr, sizeof(unit_path_arr));
|
|
|
|
|
std::string unit_path(unit_path_arr);
|
|
|
|
|
object.try_emplace("compileUnitPath", unit_path);
|
|
|
|
|
return llvm::json::Value(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-01 18:52:14 -07:00
|
|
|
/// See
|
|
|
|
|
/// https://microsoft.github.io/debug-adapter-protocol/specification#Reverse_Requests_RunInTerminal
|
|
|
|
|
llvm::json::Object
|
[vscode] Improve runInTerminal and support linux
Depends on D93874.
runInTerminal was using --wait-for, but it was some problems because it uses process polling looking for a single instance of the debuggee:
- it gets to know of the target late, which renders breakpoints in the main function almost impossible
- polling might fail if there are already other processes with the same name
- polling might also fail on some linux machine, as it's implemented with the ps command, and the ps command's args and output are not standard everywhere
As a better way to implement this so that it works well on Darwin and Linux, I'm using now the following process:
- lldb-vscode notices the runInTerminal, so it spawns lldb-vscode with a special flag --launch-target <target>. This flags tells lldb-vscode to wait to be attached and then it execs the target program. I'm using lldb-vscode itself to do this, because it makes finding the launcher program easier. Also no CMAKE INSTALL scripts are needed.
- Besides this, the debugger creates a temporary FIFO file where the launcher program will write its pid to. That way the debugger will be sure of which program to attach.
- Once attach happend, the debugger creates a second temporary file to notify the launcher program that it has been attached, so that it can then exec. I'm using this instead of using a signal or a similar mechanism because I don't want the launcher program to wait indefinitely to be attached in case the debugger crashed. That would pollute the process list with a lot of hanging processes. Instead, I'm setting a 20 seconds timeout (that's an overkill) and the launcher program seeks in intervals the second tepmorary file.
Some notes:
- I preferred not to use sockets because it requires a lot of code and I only need a pid. It would also require a lot of code when windows support is implemented.
- I didn't add Windows support, as I don't have a windows machine, but adding support for it should be easy, as the FIFO file can be implemented with a named pipe, which is standard on Windows and works pretty much the same way.
The existing test which didn't pass on Linux, now passes.
Differential Revision: https://reviews.llvm.org/D93951
2020-12-28 12:00:47 -08:00
|
|
|
CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request,
|
|
|
|
|
llvm::StringRef debug_adaptor_path,
|
2023-04-07 13:34:16 -07:00
|
|
|
llvm::StringRef comm_file,
|
|
|
|
|
lldb::pid_t debugger_pid) {
|
2020-09-01 18:52:14 -07:00
|
|
|
llvm::json::Object run_in_terminal_args;
|
|
|
|
|
// This indicates the IDE to open an embedded terminal, instead of opening the
|
|
|
|
|
// terminal in a new window.
|
|
|
|
|
run_in_terminal_args.try_emplace("kind", "integrated");
|
|
|
|
|
|
|
|
|
|
auto launch_request_arguments = launch_request.getObject("arguments");
|
|
|
|
|
// The program path must be the first entry in the "args" field
|
2023-10-19 09:48:54 -07:00
|
|
|
std::vector<std::string> args = {debug_adaptor_path.str(), "--comm-file",
|
|
|
|
|
comm_file.str()};
|
2023-04-07 13:34:16 -07:00
|
|
|
if (debugger_pid != LLDB_INVALID_PROCESS_ID) {
|
|
|
|
|
args.push_back("--debugger-pid");
|
|
|
|
|
args.push_back(std::to_string(debugger_pid));
|
|
|
|
|
}
|
|
|
|
|
args.push_back("--launch-target");
|
|
|
|
|
args.push_back(GetString(launch_request_arguments, "program").str());
|
[vscode] Improve runInTerminal and support linux
Depends on D93874.
runInTerminal was using --wait-for, but it was some problems because it uses process polling looking for a single instance of the debuggee:
- it gets to know of the target late, which renders breakpoints in the main function almost impossible
- polling might fail if there are already other processes with the same name
- polling might also fail on some linux machine, as it's implemented with the ps command, and the ps command's args and output are not standard everywhere
As a better way to implement this so that it works well on Darwin and Linux, I'm using now the following process:
- lldb-vscode notices the runInTerminal, so it spawns lldb-vscode with a special flag --launch-target <target>. This flags tells lldb-vscode to wait to be attached and then it execs the target program. I'm using lldb-vscode itself to do this, because it makes finding the launcher program easier. Also no CMAKE INSTALL scripts are needed.
- Besides this, the debugger creates a temporary FIFO file where the launcher program will write its pid to. That way the debugger will be sure of which program to attach.
- Once attach happend, the debugger creates a second temporary file to notify the launcher program that it has been attached, so that it can then exec. I'm using this instead of using a signal or a similar mechanism because I don't want the launcher program to wait indefinitely to be attached in case the debugger crashed. That would pollute the process list with a lot of hanging processes. Instead, I'm setting a 20 seconds timeout (that's an overkill) and the launcher program seeks in intervals the second tepmorary file.
Some notes:
- I preferred not to use sockets because it requires a lot of code and I only need a pid. It would also require a lot of code when windows support is implemented.
- I didn't add Windows support, as I don't have a windows machine, but adding support for it should be easy, as the FIFO file can be implemented with a named pipe, which is standard on Windows and works pretty much the same way.
The existing test which didn't pass on Linux, now passes.
Differential Revision: https://reviews.llvm.org/D93951
2020-12-28 12:00:47 -08:00
|
|
|
std::vector<std::string> target_args =
|
|
|
|
|
GetStrings(launch_request_arguments, "args");
|
|
|
|
|
args.insert(args.end(), target_args.begin(), target_args.end());
|
2020-09-01 18:52:14 -07:00
|
|
|
run_in_terminal_args.try_emplace("args", args);
|
|
|
|
|
|
|
|
|
|
const auto cwd = GetString(launch_request_arguments, "cwd");
|
|
|
|
|
if (!cwd.empty())
|
|
|
|
|
run_in_terminal_args.try_emplace("cwd", cwd);
|
|
|
|
|
|
2024-10-07 17:38:36 +01:00
|
|
|
auto envs = GetEnvironmentFromArguments(*launch_request_arguments);
|
|
|
|
|
llvm::json::Object env_json;
|
|
|
|
|
for (size_t index = 0, env_count = envs.GetNumValues(); index < env_count;
|
|
|
|
|
index++) {
|
|
|
|
|
llvm::StringRef key = envs.GetNameAtIndex(index);
|
|
|
|
|
llvm::StringRef value = envs.GetValueAtIndex(index);
|
|
|
|
|
|
|
|
|
|
if (key.empty())
|
|
|
|
|
g_dap.SendOutput(OutputType::Stderr,
|
|
|
|
|
"empty environment variable for value: \"" +
|
|
|
|
|
value.str() + '\"');
|
|
|
|
|
else
|
|
|
|
|
env_json.try_emplace(key, value);
|
2020-09-01 18:52:14 -07:00
|
|
|
}
|
|
|
|
|
run_in_terminal_args.try_emplace("env",
|
2024-10-07 17:38:36 +01:00
|
|
|
llvm::json::Value(std::move(env_json)));
|
2020-09-01 18:52:14 -07:00
|
|
|
|
2023-06-29 12:56:50 -04:00
|
|
|
return run_in_terminal_args;
|
2020-09-01 18:52:14 -07:00
|
|
|
}
|
|
|
|
|
|
[lldb-vscode] Send Selected Statistics Dump in Terminated Event
This patch will gather debug info & breakpoint info from the statistics dump (from `(SBTarget.GetStatistics())` func) and send to DAP in terminated event.
The statistics content can be huge (especially the `modules`) and dumping in full JSON can create delay in the IDE's debugging UI. (For more details, please read: https://github.com/llvm/llvm-project/commit/7bbd0fba986c241162b77b7e424ad82bc7e17b41 ). Hence, we will filter out large contents before returning it in terminated event.
It will keep all the metadata fields (those starts with "total"). For large contents, it uses the opt-out strategy. Currently it only removes the "modules" field. This way every time a new top-level field being added, we will be able to capture them from DAP log without changing lldb-vscode.
The DAP terminated event should look like
```
{
"event":"terminated",
"seq":0,
"statistics": {
"memory": <JSON string>
"targets": <JSON string>, // it's a JSON array, breakpoints info included in each target
<metadata_key: value> // pairs
},
"type":"event"
}
```
All the info above will be append to statistics field in the terminated event
Test Plan
Debugged a simple hello world program from VSCode. Exit debug session in two ways: 1) run to program exit; 2) user initiated debug session end (quit debugging before program exit).
Check DAP log and see both debug sessions have statistics returned in terminated event.
Here's an example when debugging the test program:
```
{"event":"terminated","seq":0,"statistics":{"memory":"{\"strings\":{\"bytesTotal\":1843200,\"bytesUnused\":897741,\"bytesUsed\":945459}}","targets":"[{\"breakpoints\":[{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"NameMask\":[56],\"Offset\":0,\"SkipPrologue\":true,\"SymbolNames\":[\"foo\"]},\"Type\":\"SymbolName\"},\"Hardware\":false,\"Names\":[\"vscode\"],\"SearchFilter\":{\"Options\":{},\"Type\":\"Unconstrained\"}}},\"id\":1,\"internal\":false,\"numLocations\":1,\"numResolvedLocations\":1,\"resolveTime\":0.002232},{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"Column\":0,\"Exact\":false,\"FileName\":\"/data/users/wanyi/llvm-sand/external/llvm-project/lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp\",\"Inlines\":true,\"LineNumber\":5,\"Offset\":0,\"SkipPrologue\":true},\"Type\":\"FileAndLine\"},\"Hardware\":false,\"Names\":[\"vscode\"],\"SearchFilter\":{\"Options\":{},\"Type\":\"Unconstrained\"}}},\"id\":2,\"internal\":false,\"numLocations\":0,\"numResolvedLocations\":0,\"resolveTime\":0.23203799999999999},{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"Language\":\"c\",\"NameMask\":[4,4,4,4,4,4],\"Offset\":0,\"SkipPrologue\":false,\"SymbolNames\":[\"_dl_debug_state\",\"rtld_db_dlactivity\",\"__dl_rtld_db_dlactivity\",\"r_debug_state\",\"_r_debug_state\",\"_rtld_debug_state\"]},\"Type\":\"SymbolName\"},\"Hardware\":false,\"SearchFilter\":{\"Options\":{\"ModuleList\":[\"/usr/lib64/ld-2.28.so\"]},\"Type\":\"Modules\"}}},\"id\":-1,\"internal\":true,\"kindDescription\":\"shared-library-event\",\"numLocations\":1,\"numResolvedLocations\":1,\"resolveTime\":0.00026699999999999998}],\"expressionEvaluation\":{\"failures\":0,\"successes\":0},\"firstStopTime\":0.087458974999999994,\"frameVariable\":{\"failures\":0,\"successes\":0},\"launchOrAttachTime\":0.052953161999999998,\"moduleIdentifiers\":[94554748126576,94554747837792,94554747149216,139800112130176,139800112161056,139800112206064,139800112340224,139800112509552,139800112236528],\"signals\":[{\"SIGSTOP\":1}],\"sourceMapDeduceCount\":0,\"stopCount\":8,\"targetCreateTime\":0.00057700000000000004,\"totalBreakpointResolveTime\":0.234537}]","totalDebugInfoByteSize":1668056,"totalDebugInfoEnabled":3,"totalDebugInfoIndexLoadedFromCache":0,"totalDebugInfoIndexSavedToCache":0,"totalDebugInfoIndexTime":0.027963000000000002,"totalDebugInfoParseTime":0.34354800000000002,"totalModuleCount":10,"totalModuleCountHasDebugInfo":3,"totalSymbolTableIndexTime":0.056050000000000003,"totalSymbolTableParseTime":0.23930000000000001,"totalSymbolTableStripped":0,"totalSymbolTablesLoadedFromCache":0,"totalSymbolTablesSavedToCache":0},"type":"event"}
```
Differential Revision: https://reviews.llvm.org/D137665
2022-09-10 11:27:09 -07:00
|
|
|
// Keep all the top level items from the statistics dump, except for the
|
|
|
|
|
// "modules" array. It can be huge and cause delay
|
|
|
|
|
// Array and dictionary value will return as <key, JSON string> pairs
|
|
|
|
|
void FilterAndGetValueForKey(const lldb::SBStructuredData data, const char *key,
|
|
|
|
|
llvm::json::Object &out) {
|
|
|
|
|
lldb::SBStructuredData value = data.GetValueForKey(key);
|
|
|
|
|
std::string key_utf8 = llvm::json::fixUTF8(key);
|
|
|
|
|
if (strcmp(key, "modules") == 0)
|
|
|
|
|
return;
|
|
|
|
|
switch (value.GetType()) {
|
|
|
|
|
case lldb::eStructuredDataTypeFloat:
|
|
|
|
|
out.try_emplace(key_utf8, value.GetFloatValue());
|
|
|
|
|
break;
|
2023-05-22 13:52:09 -07:00
|
|
|
case lldb::eStructuredDataTypeUnsignedInteger:
|
|
|
|
|
out.try_emplace(key_utf8, value.GetIntegerValue((uint64_t)0));
|
|
|
|
|
break;
|
|
|
|
|
case lldb::eStructuredDataTypeSignedInteger:
|
|
|
|
|
out.try_emplace(key_utf8, value.GetIntegerValue((int64_t)0));
|
[lldb-vscode] Send Selected Statistics Dump in Terminated Event
This patch will gather debug info & breakpoint info from the statistics dump (from `(SBTarget.GetStatistics())` func) and send to DAP in terminated event.
The statistics content can be huge (especially the `modules`) and dumping in full JSON can create delay in the IDE's debugging UI. (For more details, please read: https://github.com/llvm/llvm-project/commit/7bbd0fba986c241162b77b7e424ad82bc7e17b41 ). Hence, we will filter out large contents before returning it in terminated event.
It will keep all the metadata fields (those starts with "total"). For large contents, it uses the opt-out strategy. Currently it only removes the "modules" field. This way every time a new top-level field being added, we will be able to capture them from DAP log without changing lldb-vscode.
The DAP terminated event should look like
```
{
"event":"terminated",
"seq":0,
"statistics": {
"memory": <JSON string>
"targets": <JSON string>, // it's a JSON array, breakpoints info included in each target
<metadata_key: value> // pairs
},
"type":"event"
}
```
All the info above will be append to statistics field in the terminated event
Test Plan
Debugged a simple hello world program from VSCode. Exit debug session in two ways: 1) run to program exit; 2) user initiated debug session end (quit debugging before program exit).
Check DAP log and see both debug sessions have statistics returned in terminated event.
Here's an example when debugging the test program:
```
{"event":"terminated","seq":0,"statistics":{"memory":"{\"strings\":{\"bytesTotal\":1843200,\"bytesUnused\":897741,\"bytesUsed\":945459}}","targets":"[{\"breakpoints\":[{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"NameMask\":[56],\"Offset\":0,\"SkipPrologue\":true,\"SymbolNames\":[\"foo\"]},\"Type\":\"SymbolName\"},\"Hardware\":false,\"Names\":[\"vscode\"],\"SearchFilter\":{\"Options\":{},\"Type\":\"Unconstrained\"}}},\"id\":1,\"internal\":false,\"numLocations\":1,\"numResolvedLocations\":1,\"resolveTime\":0.002232},{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"Column\":0,\"Exact\":false,\"FileName\":\"/data/users/wanyi/llvm-sand/external/llvm-project/lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp\",\"Inlines\":true,\"LineNumber\":5,\"Offset\":0,\"SkipPrologue\":true},\"Type\":\"FileAndLine\"},\"Hardware\":false,\"Names\":[\"vscode\"],\"SearchFilter\":{\"Options\":{},\"Type\":\"Unconstrained\"}}},\"id\":2,\"internal\":false,\"numLocations\":0,\"numResolvedLocations\":0,\"resolveTime\":0.23203799999999999},{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"Language\":\"c\",\"NameMask\":[4,4,4,4,4,4],\"Offset\":0,\"SkipPrologue\":false,\"SymbolNames\":[\"_dl_debug_state\",\"rtld_db_dlactivity\",\"__dl_rtld_db_dlactivity\",\"r_debug_state\",\"_r_debug_state\",\"_rtld_debug_state\"]},\"Type\":\"SymbolName\"},\"Hardware\":false,\"SearchFilter\":{\"Options\":{\"ModuleList\":[\"/usr/lib64/ld-2.28.so\"]},\"Type\":\"Modules\"}}},\"id\":-1,\"internal\":true,\"kindDescription\":\"shared-library-event\",\"numLocations\":1,\"numResolvedLocations\":1,\"resolveTime\":0.00026699999999999998}],\"expressionEvaluation\":{\"failures\":0,\"successes\":0},\"firstStopTime\":0.087458974999999994,\"frameVariable\":{\"failures\":0,\"successes\":0},\"launchOrAttachTime\":0.052953161999999998,\"moduleIdentifiers\":[94554748126576,94554747837792,94554747149216,139800112130176,139800112161056,139800112206064,139800112340224,139800112509552,139800112236528],\"signals\":[{\"SIGSTOP\":1}],\"sourceMapDeduceCount\":0,\"stopCount\":8,\"targetCreateTime\":0.00057700000000000004,\"totalBreakpointResolveTime\":0.234537}]","totalDebugInfoByteSize":1668056,"totalDebugInfoEnabled":3,"totalDebugInfoIndexLoadedFromCache":0,"totalDebugInfoIndexSavedToCache":0,"totalDebugInfoIndexTime":0.027963000000000002,"totalDebugInfoParseTime":0.34354800000000002,"totalModuleCount":10,"totalModuleCountHasDebugInfo":3,"totalSymbolTableIndexTime":0.056050000000000003,"totalSymbolTableParseTime":0.23930000000000001,"totalSymbolTableStripped":0,"totalSymbolTablesLoadedFromCache":0,"totalSymbolTablesSavedToCache":0},"type":"event"}
```
Differential Revision: https://reviews.llvm.org/D137665
2022-09-10 11:27:09 -07:00
|
|
|
break;
|
|
|
|
|
case lldb::eStructuredDataTypeArray: {
|
|
|
|
|
lldb::SBStream contents;
|
|
|
|
|
value.GetAsJSON(contents);
|
|
|
|
|
out.try_emplace(key_utf8, llvm::json::fixUTF8(contents.GetData()));
|
|
|
|
|
} break;
|
|
|
|
|
case lldb::eStructuredDataTypeBoolean:
|
|
|
|
|
out.try_emplace(key_utf8, value.GetBooleanValue());
|
|
|
|
|
break;
|
|
|
|
|
case lldb::eStructuredDataTypeString: {
|
|
|
|
|
// Get the string size before reading
|
|
|
|
|
const size_t str_length = value.GetStringValue(nullptr, 0);
|
|
|
|
|
std::string str(str_length + 1, 0);
|
|
|
|
|
value.GetStringValue(&str[0], str_length);
|
|
|
|
|
out.try_emplace(key_utf8, llvm::json::fixUTF8(str));
|
|
|
|
|
} break;
|
|
|
|
|
case lldb::eStructuredDataTypeDictionary: {
|
|
|
|
|
lldb::SBStream contents;
|
|
|
|
|
value.GetAsJSON(contents);
|
|
|
|
|
out.try_emplace(key_utf8, llvm::json::fixUTF8(contents.GetData()));
|
|
|
|
|
} break;
|
|
|
|
|
case lldb::eStructuredDataTypeNull:
|
|
|
|
|
case lldb::eStructuredDataTypeGeneric:
|
|
|
|
|
case lldb::eStructuredDataTypeInvalid:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addStatistic(llvm::json::Object &event) {
|
2023-10-19 09:48:54 -07:00
|
|
|
lldb::SBStructuredData statistics = g_dap.target.GetStatistics();
|
[lldb-vscode] Send Selected Statistics Dump in Terminated Event
This patch will gather debug info & breakpoint info from the statistics dump (from `(SBTarget.GetStatistics())` func) and send to DAP in terminated event.
The statistics content can be huge (especially the `modules`) and dumping in full JSON can create delay in the IDE's debugging UI. (For more details, please read: https://github.com/llvm/llvm-project/commit/7bbd0fba986c241162b77b7e424ad82bc7e17b41 ). Hence, we will filter out large contents before returning it in terminated event.
It will keep all the metadata fields (those starts with "total"). For large contents, it uses the opt-out strategy. Currently it only removes the "modules" field. This way every time a new top-level field being added, we will be able to capture them from DAP log without changing lldb-vscode.
The DAP terminated event should look like
```
{
"event":"terminated",
"seq":0,
"statistics": {
"memory": <JSON string>
"targets": <JSON string>, // it's a JSON array, breakpoints info included in each target
<metadata_key: value> // pairs
},
"type":"event"
}
```
All the info above will be append to statistics field in the terminated event
Test Plan
Debugged a simple hello world program from VSCode. Exit debug session in two ways: 1) run to program exit; 2) user initiated debug session end (quit debugging before program exit).
Check DAP log and see both debug sessions have statistics returned in terminated event.
Here's an example when debugging the test program:
```
{"event":"terminated","seq":0,"statistics":{"memory":"{\"strings\":{\"bytesTotal\":1843200,\"bytesUnused\":897741,\"bytesUsed\":945459}}","targets":"[{\"breakpoints\":[{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"NameMask\":[56],\"Offset\":0,\"SkipPrologue\":true,\"SymbolNames\":[\"foo\"]},\"Type\":\"SymbolName\"},\"Hardware\":false,\"Names\":[\"vscode\"],\"SearchFilter\":{\"Options\":{},\"Type\":\"Unconstrained\"}}},\"id\":1,\"internal\":false,\"numLocations\":1,\"numResolvedLocations\":1,\"resolveTime\":0.002232},{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"Column\":0,\"Exact\":false,\"FileName\":\"/data/users/wanyi/llvm-sand/external/llvm-project/lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp\",\"Inlines\":true,\"LineNumber\":5,\"Offset\":0,\"SkipPrologue\":true},\"Type\":\"FileAndLine\"},\"Hardware\":false,\"Names\":[\"vscode\"],\"SearchFilter\":{\"Options\":{},\"Type\":\"Unconstrained\"}}},\"id\":2,\"internal\":false,\"numLocations\":0,\"numResolvedLocations\":0,\"resolveTime\":0.23203799999999999},{\"details\":{\"Breakpoint\":{\"BKPTOptions\":{\"AutoContinue\":false,\"ConditionText\":\"\",\"EnabledState\":true,\"IgnoreCount\":0,\"OneShotState\":false},\"BKPTResolver\":{\"Options\":{\"Language\":\"c\",\"NameMask\":[4,4,4,4,4,4],\"Offset\":0,\"SkipPrologue\":false,\"SymbolNames\":[\"_dl_debug_state\",\"rtld_db_dlactivity\",\"__dl_rtld_db_dlactivity\",\"r_debug_state\",\"_r_debug_state\",\"_rtld_debug_state\"]},\"Type\":\"SymbolName\"},\"Hardware\":false,\"SearchFilter\":{\"Options\":{\"ModuleList\":[\"/usr/lib64/ld-2.28.so\"]},\"Type\":\"Modules\"}}},\"id\":-1,\"internal\":true,\"kindDescription\":\"shared-library-event\",\"numLocations\":1,\"numResolvedLocations\":1,\"resolveTime\":0.00026699999999999998}],\"expressionEvaluation\":{\"failures\":0,\"successes\":0},\"firstStopTime\":0.087458974999999994,\"frameVariable\":{\"failures\":0,\"successes\":0},\"launchOrAttachTime\":0.052953161999999998,\"moduleIdentifiers\":[94554748126576,94554747837792,94554747149216,139800112130176,139800112161056,139800112206064,139800112340224,139800112509552,139800112236528],\"signals\":[{\"SIGSTOP\":1}],\"sourceMapDeduceCount\":0,\"stopCount\":8,\"targetCreateTime\":0.00057700000000000004,\"totalBreakpointResolveTime\":0.234537}]","totalDebugInfoByteSize":1668056,"totalDebugInfoEnabled":3,"totalDebugInfoIndexLoadedFromCache":0,"totalDebugInfoIndexSavedToCache":0,"totalDebugInfoIndexTime":0.027963000000000002,"totalDebugInfoParseTime":0.34354800000000002,"totalModuleCount":10,"totalModuleCountHasDebugInfo":3,"totalSymbolTableIndexTime":0.056050000000000003,"totalSymbolTableParseTime":0.23930000000000001,"totalSymbolTableStripped":0,"totalSymbolTablesLoadedFromCache":0,"totalSymbolTablesSavedToCache":0},"type":"event"}
```
Differential Revision: https://reviews.llvm.org/D137665
2022-09-10 11:27:09 -07:00
|
|
|
bool is_dictionary =
|
|
|
|
|
statistics.GetType() == lldb::eStructuredDataTypeDictionary;
|
|
|
|
|
if (!is_dictionary)
|
|
|
|
|
return;
|
|
|
|
|
llvm::json::Object stats_body;
|
|
|
|
|
|
|
|
|
|
lldb::SBStringList keys;
|
|
|
|
|
if (!statistics.GetKeys(keys))
|
|
|
|
|
return;
|
|
|
|
|
for (size_t i = 0; i < keys.GetSize(); i++) {
|
|
|
|
|
const char *key = keys.GetStringAtIndex(i);
|
|
|
|
|
FilterAndGetValueForKey(statistics, key, stats_body);
|
|
|
|
|
}
|
|
|
|
|
event.try_emplace("statistics", std::move(stats_body));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llvm::json::Object CreateTerminatedEventObject() {
|
|
|
|
|
llvm::json::Object event(CreateEventObject("terminated"));
|
|
|
|
|
addStatistic(event);
|
|
|
|
|
return event;
|
|
|
|
|
}
|
|
|
|
|
|
[vscode] Improve runInTerminal and support linux
Depends on D93874.
runInTerminal was using --wait-for, but it was some problems because it uses process polling looking for a single instance of the debuggee:
- it gets to know of the target late, which renders breakpoints in the main function almost impossible
- polling might fail if there are already other processes with the same name
- polling might also fail on some linux machine, as it's implemented with the ps command, and the ps command's args and output are not standard everywhere
As a better way to implement this so that it works well on Darwin and Linux, I'm using now the following process:
- lldb-vscode notices the runInTerminal, so it spawns lldb-vscode with a special flag --launch-target <target>. This flags tells lldb-vscode to wait to be attached and then it execs the target program. I'm using lldb-vscode itself to do this, because it makes finding the launcher program easier. Also no CMAKE INSTALL scripts are needed.
- Besides this, the debugger creates a temporary FIFO file where the launcher program will write its pid to. That way the debugger will be sure of which program to attach.
- Once attach happend, the debugger creates a second temporary file to notify the launcher program that it has been attached, so that it can then exec. I'm using this instead of using a signal or a similar mechanism because I don't want the launcher program to wait indefinitely to be attached in case the debugger crashed. That would pollute the process list with a lot of hanging processes. Instead, I'm setting a 20 seconds timeout (that's an overkill) and the launcher program seeks in intervals the second tepmorary file.
Some notes:
- I preferred not to use sockets because it requires a lot of code and I only need a pid. It would also require a lot of code when windows support is implemented.
- I didn't add Windows support, as I don't have a windows machine, but adding support for it should be easy, as the FIFO file can be implemented with a named pipe, which is standard on Windows and works pretty much the same way.
The existing test which didn't pass on Linux, now passes.
Differential Revision: https://reviews.llvm.org/D93951
2020-12-28 12:00:47 -08:00
|
|
|
std::string JSONToString(const llvm::json::Value &json) {
|
|
|
|
|
std::string data;
|
|
|
|
|
llvm::raw_string_ostream os(data);
|
|
|
|
|
os << json;
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 09:48:54 -07:00
|
|
|
} // namespace lldb_dap
|