[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
https://github.com/yuvald-sweet-security edited https://github.com/llvm/llvm-project/pull/131519 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
https://github.com/yuvald-sweet-security edited https://github.com/llvm/llvm-project/pull/131519 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. (PR #131544)
https://github.com/da-viper created https://github.com/llvm/llvm-project/pull/131544 The logging markers for incoming ("<--") and outgoing ("-->") messages were incorrectly reversed. from #7790d69 >From bdfcf3a3d15c2c8f72d6a553027287eb0f43a3d4 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Sun, 16 Mar 2025 23:25:58 + Subject: [PATCH] [lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. The logging markers for incoming ("<--") and outgoing ("-->") messages were incorrectly reversed. from #7790d69 --- lldb/tools/lldb-dap/Transport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/tools/lldb-dap/Transport.cpp b/lldb/tools/lldb-dap/Transport.cpp index db2d7228d3fb7..a721662a345eb 100644 --- a/lldb/tools/lldb-dap/Transport.cpp +++ b/lldb/tools/lldb-dap/Transport.cpp @@ -103,7 +103,7 @@ Expected> Transport::Read() { if (raw_json->length() != length) return createStringError("unexpected EOF parse DAP message body"); - DAP_LOG(m_log, "<-- ({0}) {1}", m_client_name, *raw_json); + DAP_LOG(m_log, "--> ({0}) {1}", m_client_name, *raw_json); return json::parse(*raw_json); } @@ -114,7 +114,7 @@ Error Transport::Write(const Message &message) { std::string json = formatv("{0}", toJSON(message)).str(); - DAP_LOG(m_log, "--> ({0}) {1}", m_client_name, json); + DAP_LOG(m_log, "<-- ({0}) {1}", m_client_name, json); std::string Output; raw_string_ostream OS(Output); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
https://github.com/yuvald-sweet-security updated https://github.com/llvm/llvm-project/pull/131519 >From 0af05f390616de8fa73fb975c4c202aac13d3745 Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Sun, 16 Mar 2025 14:08:57 + Subject: [PATCH] [lldb] Use correct path for lldb-server executable --- lldb/tools/lldb-server/lldb-platform.cpp | 19 +-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 880b45b989b9c..32e31ff70c5fd 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -545,13 +545,28 @@ int main_platform(int argc, char *argv[]) { MainLoop main_loop; { +char progpath[1024]; +#if defined(_WIN32) +if (GetModuleFileName(NULL, progpath, sizeof(progpath)) == 0) { + printf("Error retrieving executable path.\n"); + return 1; +} +#else +ssize_t len = readlink("/proc/self/exe", progpath, sizeof(progpath) - 1); +if (len == -1) { + perror("readlink"); + return 1; +} +progpath[len] = '\0'; +#endif + llvm::Expected> platform_handles = platform_sock->Accept( -main_loop, [progname, gdbserver_port, &inferior_arguments, log_file, +main_loop, [progpath, gdbserver_port, &inferior_arguments, log_file, log_channels, &main_loop, &platform_handles](std::unique_ptr sock_up) { printf("Connection established.\n"); - Status error = spawn_process(progname, sock_up.get(), + Status error = spawn_process(progpath, sock_up.get(), gdbserver_port, inferior_arguments, log_file, log_channels, main_loop); if (error.Fail()) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][lldb-dap] setVariable request should send the correct response (PR #130773)
https://github.com/da-viper edited https://github.com/llvm/llvm-project/pull/130773 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][lldb-dap] setVariable request should send the correct response (PR #130773)
https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/130773 >From 1a70dca11783f11b267d0d144311994dfba79733 Mon Sep 17 00:00:00 2001 From: Ezike Ebuka Date: Tue, 11 Mar 2025 13:15:16 + Subject: [PATCH] [lldb][lldb-dap] setVariable request should send the correct response The display value was incorrectly sent as "result" instead of "value". --- .../tools/lldb-dap/variables/TestDAP_variables.py | 14 -- .../lldb-dap/Handler/SetVariableRequestHandler.cpp | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py b/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py index ee5b49de14d98..286bf3390a440 100644 --- a/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py +++ b/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py @@ -313,10 +313,20 @@ def do_test_scopes_variables_setVariable_evaluate( # Set a variable value whose name is synthetic, like a variable index # and verify the value by reading it -self.dap_server.request_setVariable(varRef, "[0]", 100) +variable_value = 100 +response = self.dap_server.request_setVariable(varRef, "[0]", variable_value) +# Verify dap sent the correct response +verify_response = { +"type": "int", +"value": str(variable_value), +"variablesReference": 0, +} +for key, value in verify_response.items(): +self.assertEqual(value, response["body"][key]) + response = self.dap_server.request_variables(varRef, start=0, count=1) self.verify_variables( -make_buffer_verify_dict(0, 1, 100), response["body"]["variables"] +make_buffer_verify_dict(0, 1, variable_value), response["body"]["variables"] ) # Set a variable value whose name is a real child value, like "pt.x" diff --git a/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp index 7d2f13f0a327e..8b46490d6f4f2 100644 --- a/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp @@ -146,7 +146,7 @@ void SetVariableRequestHandler::operator()( bool success = variable.SetValueFromCString(value.data(), error); if (success) { VariableDescription desc(variable, dap.enable_auto_variable_summaries); - EmplaceSafeString(body, "result", desc.display_value); + EmplaceSafeString(body, "value", desc.display_value); EmplaceSafeString(body, "type", desc.display_type_name); // We don't know the index of the variable in our dap.variables ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. (PR #131544)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Ebuka Ezike (da-viper) Changes The logging markers for incoming ("<--") and outgoing ("-->") messages were incorrectly reversed. from #7790d69 --- Full diff: https://github.com/llvm/llvm-project/pull/131544.diff 1 Files Affected: - (modified) lldb/tools/lldb-dap/Transport.cpp (+2-2) ``diff diff --git a/lldb/tools/lldb-dap/Transport.cpp b/lldb/tools/lldb-dap/Transport.cpp index db2d7228d3fb7..a721662a345eb 100644 --- a/lldb/tools/lldb-dap/Transport.cpp +++ b/lldb/tools/lldb-dap/Transport.cpp @@ -103,7 +103,7 @@ Expected> Transport::Read() { if (raw_json->length() != length) return createStringError("unexpected EOF parse DAP message body"); - DAP_LOG(m_log, "<-- ({0}) {1}", m_client_name, *raw_json); + DAP_LOG(m_log, "--> ({0}) {1}", m_client_name, *raw_json); return json::parse(*raw_json); } @@ -114,7 +114,7 @@ Error Transport::Write(const Message &message) { std::string json = formatv("{0}", toJSON(message)).str(); - DAP_LOG(m_log, "--> ({0}) {1}", m_client_name, json); + DAP_LOG(m_log, "<-- ({0}) {1}", m_client_name, json); std::string Output; raw_string_ostream OS(Output); `` https://github.com/llvm/llvm-project/pull/131544 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 125c4db - [lldb][lldb-dap] setVariable request should send the correct response (#130773)
Author: Ebuka Ezike Date: 2025-03-16T23:28:25Z New Revision: 125c4db7301875cae928406043f02ed5b1133195 URL: https://github.com/llvm/llvm-project/commit/125c4db7301875cae928406043f02ed5b1133195 DIFF: https://github.com/llvm/llvm-project/commit/125c4db7301875cae928406043f02ed5b1133195.diff LOG: [lldb][lldb-dap] setVariable request should send the correct response (#130773) The display value was incorrectly sent as "result" instead of "value". Added: Modified: lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp Removed: diff --git a/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py b/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py index ee5b49de14d98..286bf3390a440 100644 --- a/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py +++ b/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py @@ -313,10 +313,20 @@ def do_test_scopes_variables_setVariable_evaluate( # Set a variable value whose name is synthetic, like a variable index # and verify the value by reading it -self.dap_server.request_setVariable(varRef, "[0]", 100) +variable_value = 100 +response = self.dap_server.request_setVariable(varRef, "[0]", variable_value) +# Verify dap sent the correct response +verify_response = { +"type": "int", +"value": str(variable_value), +"variablesReference": 0, +} +for key, value in verify_response.items(): +self.assertEqual(value, response["body"][key]) + response = self.dap_server.request_variables(varRef, start=0, count=1) self.verify_variables( -make_buffer_verify_dict(0, 1, 100), response["body"]["variables"] +make_buffer_verify_dict(0, 1, variable_value), response["body"]["variables"] ) # Set a variable value whose name is a real child value, like "pt.x" diff --git a/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp index 3ab1bb32fd18e..a7896b7fefa29 100644 --- a/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp @@ -146,7 +146,7 @@ void SetVariableRequestHandler::operator()( bool success = variable.SetValueFromCString(value.data(), error); if (success) { VariableDescription desc(variable, dap.enable_auto_variable_summaries); - EmplaceSafeString(body, "result", desc.display_value); + EmplaceSafeString(body, "value", desc.display_value); EmplaceSafeString(body, "type", desc.display_type_name); // We don't know the index of the variable in our dap.variables ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][lldb-dap] setVariable request should send the correct response (PR #130773)
https://github.com/da-viper closed https://github.com/llvm/llvm-project/pull/130773 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
https://github.com/yuvald-sweet-security updated https://github.com/llvm/llvm-project/pull/131519 >From bbfae1028b2c47b6fe422f71516fb486d94f406b Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Sun, 16 Mar 2025 14:08:57 + Subject: [PATCH] [lldb] Use correct path for lldb-server executable --- lldb/tools/lldb-server/lldb-platform.cpp | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 880b45b989b9c..ac0fd64a14715 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -545,13 +545,28 @@ int main_platform(int argc, char *argv[]) { MainLoop main_loop; { +char progpath[1024]; +#if defined(_WIN32) +if (GetModuleFileName(NULL, progpath, sizeof(progpath)) == 0) { + printf("Error retrieving executable path.\n"); + return 1; +} +#else +ssize_t len = readlink("/proc/self/exe", progpath, sizeof(progpath) - 1); +if (len == -1) { + perror("readlink"); + return 1; +} +progpath[len] = '\0'; +#endif + llvm::Expected> platform_handles = platform_sock->Accept( main_loop, [progname, gdbserver_port, &inferior_arguments, log_file, log_channels, &main_loop, &platform_handles](std::unique_ptr sock_up) { printf("Connection established.\n"); - Status error = spawn_process(progname, sock_up.get(), + Status error = spawn_process(progpath, sock_up.get(), gdbserver_port, inferior_arguments, log_file, log_channels, main_loop); if (error.Fail()) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 8705e48 - [lldb] Remove use of comma operator (NFC) (#131233)
Author: Dave Lee Date: 2025-03-16T08:41:55-07:00 New Revision: 8705e489dc17eb7124aca5070201d2dd234f97c1 URL: https://github.com/llvm/llvm-project/commit/8705e489dc17eb7124aca5070201d2dd234f97c1 DIFF: https://github.com/llvm/llvm-project/commit/8705e489dc17eb7124aca5070201d2dd234f97c1.diff LOG: [lldb] Remove use of comma operator (NFC) (#131233) No reason for the comma operator, make this more conventional with two statements. Added: Modified: lldb/source/ValueObject/ValueObjectSyntheticFilter.cpp Removed: diff --git a/lldb/source/ValueObject/ValueObjectSyntheticFilter.cpp b/lldb/source/ValueObject/ValueObjectSyntheticFilter.cpp index d49c27f0006bc..ae2b9bebbb12d 100644 --- a/lldb/source/ValueObject/ValueObjectSyntheticFilter.cpp +++ b/lldb/source/ValueObject/ValueObjectSyntheticFilter.cpp @@ -362,7 +362,9 @@ lldb::ValueObjectSP ValueObjectSynthetic::GetNonSyntheticValue() { } void ValueObjectSynthetic::CopyValueData(ValueObject *source) { - m_value = (source->UpdateValueIfNeeded(), source->GetValue()); + if (!source->UpdateValueIfNeeded()) +return; + m_value = source->GetValue(); ExecutionContext exe_ctx(GetExecutionContextRef()); m_error = m_value.GetValueAsData(&exe_ctx, m_data, GetModule().get()); } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Remove use of comma operator (NFC) (PR #131233)
https://github.com/kastiglione closed https://github.com/llvm/llvm-project/pull/131233 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)
https://github.com/JDevlieghere approved this pull request. LGTM modulo comments https://github.com/llvm/llvm-project/pull/130090 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. (PR #131544)
JDevlieghere wrote: Huh, you're right, the direction was changed, but I actually think the current direction is more intuitive. @ashgti did you change this on purpose? https://github.com/llvm/llvm-project/pull/131544 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)
@@ -1,12 +1,12 @@ -//===-- Protocol.cpp --===// +//===-- ProtocolBase.cpp --===// JDevlieghere wrote: Why not just Protocol? Do you think that's to confusing with the other Protocol classes? https://github.com/llvm/llvm-project/pull/130090 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)
@@ -663,58 +671,64 @@ void DAP::SetTarget(const lldb::SBTarget target) { } bool DAP::HandleObject(const protocol::Message &M) { - // FIXME: Directly handle `Message` instead of serializing to JSON. - llvm::json::Value v = toJSON(M); - llvm::json::Object object = *v.getAsObject(); - const auto packet_type = GetString(object, "type"); - if (packet_type == "request") { -const auto command = GetString(object, "command"); - -auto new_handler_pos = request_handlers.find(command); -if (new_handler_pos != request_handlers.end()) { - (*new_handler_pos->second)(object); + if (const auto *req = std::get_if(&M)) { +auto handler_pos = request_handlers.find(req->command); +if (handler_pos != request_handlers.end()) { + (*handler_pos->second)(*req); return true; // Success } DAP_LOG(log, "({0}) error: unhandled command '{1}'", -transport.GetClientName(), command); +transport.GetClientName(), req->command); return false; // Fail } - if (packet_type == "response") { -auto id = GetInteger(object, "request_seq").value_or(0); - + if (const auto *resp = std::get_if(&M)) { std::unique_ptr response_handler; { std::lock_guard locker(call_mutex); - auto inflight = inflight_reverse_requests.find(id); + auto inflight = inflight_reverse_requests.find(resp->request_seq); if (inflight != inflight_reverse_requests.end()) { response_handler = std::move(inflight->second); inflight_reverse_requests.erase(inflight); } } if (!response_handler) - response_handler = std::make_unique("", id); + response_handler = + std::make_unique("", resp->request_seq); // Result should be given, use null if not. -if (GetBoolean(object, "success").value_or(false)) { - llvm::json::Value Result = nullptr; - if (auto *B = object.get("body")) -Result = std::move(*B); - (*response_handler)(Result); +if (resp->success) { + (*response_handler)(resp->body); } else { - llvm::StringRef message = GetString(object, "message"); - if (message.empty()) { -message = "Unknown error, response failed"; + std::string message = "Unknown error, response failed"; + if (resp->message) { +message = std::visit( +llvm::makeVisitor( +[](const std::string &message) -> std::string { + return message; +}, +[](const protocol::Response::Message &message) -> std::string { JDevlieghere wrote: Any reason these can't remain StringRefs? They're all string literals, right? https://github.com/llvm/llvm-project/pull/130090 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
https://github.com/yuvald-sweet-security created https://github.com/llvm/llvm-project/pull/131519 Hey, This solves an issue where running lldb-server-20 with a non-absolute path (for example, when it's installed into `/usr/bin` and the user runs it as `lldb-server-20 ...` and not `/usr/bin/lldb-server-20 ...`) fails with `error: spawn_process failed: execve failed: No such file or directory`. The underlying issue is that when run that way, it attempts to execute a binary named `lldb-server-20` from its current directory. This is also a mild security hazard because lldb-server is often being run as root in the directory `/tmp`, meaning that an unprivileged user can create the file `/tmp/lldb-server-20` and lldb-server will execute it as root. I haven't previously contributed to this project; if you want me to change anything in the code please don't hesitate to let me know. >From 2ffe1c4d93b05b3549ff7bc6761d9a08f82e331d Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Sun, 16 Mar 2025 14:08:57 + Subject: [PATCH] [lldb] Use correct path for lldb-server executable --- lldb/tools/lldb-server/lldb-platform.cpp | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 880b45b989b9c..103e1ac02843d 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -545,13 +545,28 @@ int main_platform(int argc, char *argv[]) { MainLoop main_loop; { +char progpath[1024]; +#if defined(_WIN32) +if (GetModuleFileName(NULL, progpath, sizeof(progpath)) == 0) { + printf("Error retrieving executable path.\n"); + return 1; +} +#else +ssize_t len = readlink("/proc/self/exe", progpath, sizeof(progpath) - 1); +if (len == -1) { + perror("readlink"); + return 1; +} +path[len] = '\0'; +#endif + llvm::Expected> platform_handles = platform_sock->Accept( main_loop, [progname, gdbserver_port, &inferior_arguments, log_file, log_channels, &main_loop, &platform_handles](std::unique_ptr sock_up) { printf("Connection established.\n"); - Status error = spawn_process(progname, sock_up.get(), + Status error = spawn_process(progpath, sock_up.get(), gdbserver_port, inferior_arguments, log_file, log_channels, main_loop); if (error.Fail()) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Yuval Deutscher (yuvald-sweet-security) Changes Hey, This solves an issue where running lldb-server-20 with a non-absolute path (for example, when it's installed into `/usr/bin` and the user runs it as `lldb-server-20 ...` and not `/usr/bin/lldb-server-20 ...`) fails with `error: spawn_process failed: execve failed: No such file or directory`. The underlying issue is that when run that way, it attempts to execute a binary named `lldb-server-20` from its current directory. This is also a mild security hazard because lldb-server is often being run as root in the directory `/tmp`, meaning that an unprivileged user can create the file `/tmp/lldb-server-20` and lldb-server will execute it as root. I haven't previously contributed to this project; if you want me to change anything in the code please don't hesitate to let me know. --- Full diff: https://github.com/llvm/llvm-project/pull/131519.diff 1 Files Affected: - (modified) lldb/tools/lldb-server/lldb-platform.cpp (+16-1) ``diff diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 880b45b989b9c..103e1ac02843d 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -545,13 +545,28 @@ int main_platform(int argc, char *argv[]) { MainLoop main_loop; { +char progpath[1024]; +#if defined(_WIN32) +if (GetModuleFileName(NULL, progpath, sizeof(progpath)) == 0) { + printf("Error retrieving executable path.\n"); + return 1; +} +#else +ssize_t len = readlink("/proc/self/exe", progpath, sizeof(progpath) - 1); +if (len == -1) { + perror("readlink"); + return 1; +} +path[len] = '\0'; +#endif + llvm::Expected> platform_handles = platform_sock->Accept( main_loop, [progname, gdbserver_port, &inferior_arguments, log_file, log_channels, &main_loop, &platform_handles](std::unique_ptr sock_up) { printf("Connection established.\n"); - Status error = spawn_process(progname, sock_up.get(), + Status error = spawn_process(progpath, sock_up.get(), gdbserver_port, inferior_arguments, log_file, log_channels, main_loop); if (error.Fail()) { `` https://github.com/llvm/llvm-project/pull/131519 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/131519 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
@@ -0,0 +1,64 @@ +""" +Make sure 'frame var' using DIL parser/evaultor works for local variables. +""" + +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +from lldbsuite.test import lldbutil + +import os +import shutil +import time + + +class TestFrameVarDILLocalVars(TestBase): +# If your test case doesn't stress debug info, then +# set this to true. That way it won't be run once for +# each debug info format. +NO_DEBUG_INFO_TESTCASE = True + +def test_frame_var(self): +self.build() +self.do_test() + +def do_test(self): +target = self.createTestTarget() + +# Now create a breakpoint in main.c at the source matching +# "Set a breakpoint here" +breakpoint = target.BreakpointCreateBySourceRegex( +"Set a breakpoint here", lldb.SBFileSpec("main.cpp") +) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT +) + +error = lldb.SBError() +# This is the launch info. If you want to launch with arguments or +# environment variables, add them using SetArguments or +# SetEnvironmentEntries + +launch_info = target.GetLaunchInfo() +process = target.Launch(launch_info, error) +self.assertTrue(process, PROCESS_IS_VALID) + +# Did we hit our breakpoint? +from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint + +threads = get_threads_stopped_at_breakpoint(process, breakpoint) +self.assertEqual( +len(threads), 1, "There should be a thread stopped at our breakpoint" +) +# The hit count for the breakpoint should be 1. +self.assertEqual(breakpoint.GetHitCount(), 1) + +frame = threads[0].GetFrameAtIndex(0) +command_result = lldb.SBCommandReturnObject() +interp = self.dbg.GetCommandInterpreter() + +self.expect("settings set target.experimental.use-DIL true", substrs=[""]) +self.expect("frame variable a", substrs=["1"]) +self.expect("frame variable b", substrs=["2"]) +self.expect("frame variable c", substrs=["\\xfd"]) +self.expect("frame variable s", substrs=["4"]) cmtice wrote: I've updated the tests to use `expect_var_path` instead of `expect` everywhere that I could make it work. https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
@@ -0,0 +1,102 @@ +//===-- DILEval.h ---*- C++ -*-===// +// +// 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 +// +//===--===// + +#ifndef LLDB_VALUEOBJECT_DILEVAL_H +#define LLDB_VALUEOBJECT_DILEVAL_H + +#include "lldb/ValueObject/DILAST.h" +#include "lldb/ValueObject/DILParser.h" +#include +#include + +namespace lldb_private::dil { + +/// Class used to store & manipulate information about identifiers. +class IdentifierInfo { +public: + enum class Kind { +eValue, +eContextArg, + }; + + static std::unique_ptr FromValue(ValueObject &valobj) { +CompilerType type; +type = valobj.GetCompilerType(); +return std::unique_ptr( +new IdentifierInfo(Kind::eValue, type, valobj.GetSP(), {})); + } + + static std::unique_ptr FromContextArg(CompilerType type) { +lldb::ValueObjectSP empty_value; +return std::unique_ptr( +new IdentifierInfo(Kind::eContextArg, type, empty_value, {})); + } + + Kind GetKind() const { return m_kind; } + lldb::ValueObjectSP GetValue() const { return m_value; } + + CompilerType GetType() { return m_type; } + bool IsValid() const { return m_type.IsValid(); } + + IdentifierInfo(Kind kind, CompilerType type, lldb::ValueObjectSP value, + std::vector path) + : m_kind(kind), m_type(type), m_value(std::move(value)) {} + +private: + Kind m_kind; + CompilerType m_type; + lldb::ValueObjectSP m_value; +}; + +/// Given the name of an identifier (variable name, member name, type name, +/// etc.), find the ValueObject for that name (if it exists), excluding global +/// variables, and create and return an IdentifierInfo object containing all +/// the relevant information about that object (for DIL parsing and +/// evaluating). +std::unique_ptr +LookupIdentifier(llvm::StringRef name_ref, std::shared_ptr frame_sp, + lldb::DynamicValueType use_dynamic, + CompilerType *scope_ptr = nullptr); + +/// Given the name of an identifier, check to see if it matches the name of a +/// global variable. If so, find the ValueObject for that global variable, and +/// create and return an IdentifierInfo object containing all the relevant +/// informatin about it. +std::unique_ptr LookupGlobalIdentifier( +llvm::StringRef name_ref, std::shared_ptr frame_sp, +lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic, +CompilerType *scope_ptr = nullptr); cmtice wrote: I'm not sure...in the full implementation there are several places where these get called from the Parser. But we haven't finished (yet) migrating all the error checking from the parser to the interpreter. When that's done maybe these won't need to be called from the Parser. For now, it might be better to leave them public. https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
cmtice wrote: I think I have addressed all of the remaining review comments/questions. Please review this again when you have a few minutes. Thanks! https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)
@@ -162,4 +162,13 @@ GetEnvironmentFromArguments(const llvm::json::Object &arguments) { return envs; } +llvm::Error takeError(const lldb::SBError &error) { JDevlieghere wrote: How about `ToError` to match `Status::ToError`? ```suggestion llvm::Error ToError(const lldb::SBError &error) { ``` https://github.com/llvm/llvm-project/pull/130090 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
cmtice wrote: > > > Didn't quite finish, but this is what I have so far. I am wondering about > > > the usefulness of the `IdentifierInfo`. It started out its existence in a > > > completely different world than what we have now -- where the operations > > > were mainly defined on types instead of values. Does it bring us anything > > > in the new setup or could we replace it by passing ValueObjects directly? > > > > > > When doing straight variable name lookup, I agree that there's not much > > added benefit to using the IdentifierNodes, but they're needed more (at the > > moment) when we're looking up field member names. Unless you strongly > > object, I'd like to keep them for now, and maybe revisit their usefulness > > when looking at the PR that handles field/member name resolution. > > I'm somewhat tempted to say we should do the opposite (remove it now, and > reintroduce it later if it is needed), but it would be nice to avoid doing > that work if it's going to be reintroduced anyway. Can you explain why you > think it is necessary for child member resolution (i.e., what does it tell > you that cannot be obtained from a ValueObject representing the child member)? > I've figured out how to make removing IdentifierInfo work. Done now. https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Make breakpoint stop reason more accurate for function breakpoints (PR #130841)
@@ -392,9 +391,59 @@ struct DAP { void SetThreadFormat(llvm::StringRef format); - InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id); + template + BreakpointType *GetBreakpointFromStopReason(lldb::SBThread &thread) { +// Check to see if have hit the breakpoint and change the +// reason accordingly, but only do so if all breakpoints that were +// hit are of . +const auto num = thread.GetStopReasonDataCount(); +BreakpointType *bp = nullptr; +for (size_t i = 0; i < num; i += 2) { + lldb::break_id_t bp_id = thread.GetStopReasonDataAtIndex(i); + // If any breakpoint is not the , then stop and + // report this as a normal breakpoint + bp = GetBreakpoint(bp_id); + if (bp == nullptr) +return nullptr; +} +return bp; + } + + template + BreakpointType *GetBreakpoint(const lldb::break_id_t bp_id); + + template <> + FunctionBreakpoint * + GetBreakpoint(const lldb::break_id_t bp_id) { +for (auto &bp : function_breakpoints) { Jlalond wrote: Didn't realize they're all different. Let's not worry about it https://github.com/llvm/llvm-project/pull/130841 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
cmtice wrote: > The other advantage of the diagnostic manager with the details et al, is that > lldb can use the structure in the diagnostic messages to have the error > message include a pointer to the place of the error in the original message, > like: > > ``` > (lldb) expr edgeSet.not_there > ^ > error: no member named 'not_there' in 'std::map std::list>' > ``` > > It would be nice to get that working for DIL expressions as well. Done. https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
cmtice wrote: > NewFormatDiagnostics looks okay. It's longer than the old version, but it's > straight-forward linear code, so I don't have a problem with that. > > It's true that the system was designed to handle multiple errors, but it > doesn't mean you have to use it that way. For me, the main value in it is the > consistency of the error format wr.t. the expression parser (I don't > particularly care about the new fancy format, but I think it's good to use > the same one in both places). Ok, I've updated the code to use the NewFormatDiagnostics (now just called FormatDiagnostics). https://github.com/llvm/llvm-project/pull/120971 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
@@ -0,0 +1,273 @@ +//===-- DILEval.cpp ---===// +// +// 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 +// +//===--===// + +#include "lldb/ValueObject/DILEval.h" +#include "lldb/Symbol/VariableList.h" +#include "lldb/Target/RegisterContext.h" +#include "lldb/ValueObject/DILAST.h" +#include "lldb/ValueObject/ValueObject.h" +#include "lldb/ValueObject/ValueObjectRegister.h" +#include "lldb/ValueObject/ValueObjectVariable.h" +#include "llvm/Support/FormatAdapters.h" +#include + +namespace lldb_private::dil { + +static lldb::ValueObjectSP LookupStaticIdentifier( +VariableList &variable_list, std::shared_ptr exe_scope, +llvm::StringRef name_ref, llvm::StringRef unqualified_name) { + // First look for an exact match to the (possibly) qualified name. + for (const lldb::VariableSP &var_sp : variable_list) { +lldb::ValueObjectSP valobj_sp( +ValueObjectVariable::Create(exe_scope.get(), var_sp)); +if (valobj_sp && valobj_sp->GetVariable() && +(valobj_sp->GetVariable()->NameMatches(ConstString(name_ref + return valobj_sp; + } + + // If the qualified name is the same as the unqualfied name, there's nothing + // more to be done. + if (name_ref == unqualified_name) +return nullptr; + + // We didn't match the qualified name; try to match the unqualified name. + for (const lldb::VariableSP &var_sp : variable_list) { +lldb::ValueObjectSP valobj_sp( +ValueObjectVariable::Create(exe_scope.get(), var_sp)); +if (valobj_sp && valobj_sp->GetVariable() && +(valobj_sp->GetVariable()->NameMatches(ConstString(unqualified_name + return valobj_sp; + } + + return nullptr; +} + +static lldb::VariableSP DILFindVariable(ConstString name, +lldb::VariableListSP variable_list) { + lldb::VariableSP exact_match; + std::vector possible_matches; + + typedef std::vector collection; + typedef collection::iterator iterator; + + iterator pos, end = variable_list->end(); + for (pos = variable_list->begin(); pos != end; ++pos) { +llvm::StringRef str_ref_name = pos->get()->GetName().GetStringRef(); +// Check for global vars, which might start with '::'. +str_ref_name.consume_front("::"); + +if (str_ref_name == name.GetStringRef()) + possible_matches.push_back(*pos); +else if (pos->get()->NameMatches(name)) + possible_matches.push_back(*pos); + } + + // Look for exact matches (favors local vars over global vars) + auto exact_match_it = + llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) { +return var_sp->GetName() == name; + }); + + if (exact_match_it != possible_matches.end()) +exact_match = *exact_match_it; + + if (!exact_match) +// Look for a global var exact match. +for (auto var_sp : possible_matches) { + llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef(); + str_ref_name.consume_front("::"); + if (str_ref_name == name.GetStringRef()) { +exact_match = var_sp; +break; + } +} + + if (!exact_match && possible_matches.size() == 1) +exact_match = possible_matches[0]; + + return exact_match; +} + +std::unique_ptr LookupGlobalIdentifier( +llvm::StringRef name_ref, std::shared_ptr stack_frame, +lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic, +CompilerType *scope_ptr) { + // First look for match in "local" global variables. + lldb::VariableListSP variable_list(stack_frame->GetInScopeVariableList(true)); + name_ref.consume_front("::"); + + lldb::ValueObjectSP value_sp; + if (variable_list) { +lldb::VariableSP var_sp = +DILFindVariable(ConstString(name_ref), variable_list); +if (var_sp) + value_sp = + stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic); + } + + if (value_sp) +return IdentifierInfo::FromValue(*value_sp); + + // Also check for static global vars. + if (variable_list) { +const char *type_name = ""; +if (scope_ptr) + type_name = scope_ptr->GetCanonicalType().GetTypeName().AsCString(); +std::string name_with_type_prefix = +llvm::formatv("{0}::{1}", type_name, name_ref).str(); +value_sp = LookupStaticIdentifier(*variable_list, stack_frame, + name_with_type_prefix, name_ref); +if (!value_sp) + value_sp = LookupStaticIdentifier(*variable_list, stack_frame, name_ref, +name_ref); + } + + if (value_sp) +return IdentifierInfo::FromValue(*value_sp); + + // Check for match in modules global variables. + VariableList modules_var_list; + target_sp->GetImages().FindGlobalVariables( + ConstString(name_
[Lldb-commits] [lldb] [lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. (PR #131544)
ashgti wrote: > Huh, you're right, the direction was changed, but I actually think the > current direction is more intuitive. > > @ashgti did you change this on purpose? I didn’t mean to change it but I’m fine with either form. https://github.com/llvm/llvm-project/pull/131544 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/130090 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. (PR #131544)
https://github.com/ashgti approved this pull request. https://github.com/llvm/llvm-project/pull/131544 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits