[Lldb-commits] [lldb] [lldb] [llgs] Fix assertion in Handle_qfThreadInfo (PR #88279)
https://github.com/mgorny approved this pull request. Sure, I suppose it makes sense. Thanks! https://github.com/llvm/llvm-project/pull/88279 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: I'm sorry for the complexity. I've finally gotten around to figuring it out, and it turns out it's a problem with CMake files: #79305 fixes it for me. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: `LLVM_DIR` and `Clang_DIR` are merely hints to `find_package()`. If you need to pass them, it simply means you haven't set `PATH` correctly and CMake can't find installed LLVM/Clang. However, that shouldn't make any difference as long as you provide paths to **installed** LLVM/Clang, and not to the source/build directory. That said, you may actually need to remove the build directory because I don't know if things don't leak through. No, I don't have a "ready" configuration. You could start off `gentoo/stage3` and install LLVM/Clang/LLDB live ebuilds to reproduce but that's a lot of effort, and I don't think it's worth your time. Perhaps I should just send the "obvious" fix without bothering you. I can reproduce it anytime, and I doubt there's any other fix possible than adding `LLVMDebuginfod` library to `libLLVM`. I just need a lot of energy to start contributing to LLVM because it's painful. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: Ah, sorry, I didn't notice that. We're not passing `LLVM_DIR` at all. LLDB is able to find installed LLVM & Clang via `PATH`, and that's all it needed. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: Ping. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: It's linking to `/home/freik/src/rel-llvm/lib/libLLVMDebuginfod.a`, i.e. the leftover build directory in your case. It doesn't exist anymore in our case. Try removing it, that should trigger the error. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: I'm afraid that log's non-verbose (i.e. missing `-v`), so it doesn't tell me which libraries are being linked. Also, I don't think I'll be able to tell much without logs for all of cmake, build and install of both LLVM and LLDB. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: Did you `ninja install-distribution` rather than regular `install`? Did it pick the right installation? Could you attach the build logs? https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: "Dylib" is LLVM-speech for `libLLVM.so` ("shared libraries" refer to individual split libraries, while "dylib" refers to the monolith), as in `-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON`. And yes, that + standalone build with full *source* repository but linking against LLVM+Clang installed with `install-distribution` target. And yeah, if you make a patch to add LLVMDebuginfod to libLLVM, I can test that here. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: I've also confirmed that installing `LLVMDebuginfod` target won't help since it references other internal targets that are created at build-time and not included as part of the installed CMake configuration: ``` CMake Error at /usr/lib/llvm/18/lib64/cmake/llvm/LLVMExports.cmake:90 (set_target_properties): The link interface of target "LLVMDebuginfod" contains: httplib::httplib but the target was not found. Possible reasons include: * There is a typo in the target name. * A find_package call is missing for an IMPORTED target. * An ALIAS target is missing. Call Stack (most recent call first): /usr/lib/llvm/18/lib64/cmake/llvm/LLVMConfig.cmake:355 (include) cmake/modules/LLDBStandalone.cmake:9 (find_package) CMakeLists.txt:34 (include) ``` I suspect that even if we hadn't used the dylib at all and installed all static libraries, it would be impossible to build LLDB against this install of LLVM as it wouldn't know about `httplib::httplib` — that is, unless LLVM was built without httplib support. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: I'm sorry for not getting back to you earlier. The log relevant to building LLVM itself is this (22M uncompressed): [sys-devel:llvm-18.0.0_pre20231206:20231206-072428.log.gz](https://github.com/llvm/llvm-project/files/13627566/sys-devel.llvm-18.0.0_pre20231206.20231206-072428.log.gz) I think the most relevant part is: ``` -DLLVM_DISTRIBUTION_COMPONENTS="LLVM;LTO;Remarks;llvm-config;cmake-exports;llvm-headers;LLVMDemangle;LLVMSupport;LLVMTableGen;llvm_gtest;llvm_gtest_main;LLVMTestingAnnotations;LLVMTestingSupport;llvm-tblgen;FileCheck;llvm-PerfectShuffle;count;not;yaml-bench;UnicodeNameMappingGenerator;bugpoint;dsymutil;llc;lli;lli-child-target;llvm-addr2line;llvm-ar;llvm-as;llvm-bcanalyzer;llvm-bitcode-strip;llvm-c-test;llvm-cat;llvm-cfi-verify;llvm-config;llvm-cov;llvm-cvtres;llvm-cxxdump;llvm-cxxfilt;llvm-cxxmap;llvm-debuginfo-analyzer;llvm-debuginfod-find;llvm-diff;llvm-dis;llvm-dlltool;llvm-dwarfdump;llvm-dwarfutil;llvm-dwp;llvm-exegesis;llvm-extract;llvm-gsymutil;llvm-ifs;llvm-install-name-tool;llvm-jitlink;llvm-jitlink-executor;llvm-lib;llvm-libtool-darwin;llvm-link;llvm-lipo;llvm-lto;llvm-lto2;llvm-mc;llvm-mca;llvm-ml;llvm-modextract;llvm-mt;llvm-nm;llvm-objcopy;llvm-objdump;llvm-opt-report;llvm-otool;llvm-pdbutil;llvm-profdata;llvm-profgen;llvm-ranlib;llvm-rc;llvm-readelf;llvm-readobj;llvm-readtapi;llvm-reduce;llvm-remarkutil;llvm-rtdyld;llvm-sim;llvm-size;llvm-split;llvm-stress;llvm-strings;llvm-strip;llvm-symbolizer;llvm-tli-checker;llvm-undname;llvm-windres;llvm-xray;obj2yaml;opt;sancov;sanstats;split-file;verify-uselistorder;yaml2obj;opt-viewer;docs-dsymutil-man;docs-llvm-dwarfdump-man;docs-llvm-man;docs-llvm-html;LLVMgold;llvm-debuginfod" ``` We don't install `LLVMDebuginfod.a` at all right now. I suppose I could try doing that but last we tried to do something similar, all hell broke loose because of its dependency on other libraries from LLVM. It's a mess, I'm afraid. At this point, I think the only reasonable solution here is to include `LLVMDebuginfod` in `libLLVM`. https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [llvm] [lldb] DEBUGINFOD based DWP acquisition for LLDB (PR #70996)
mgorny wrote: This change broke building against LLVM dylib: ``` /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lLLVMDebuginfod: No such file or directory collect2: error: ld returned 1 exit status samu: subcommand failed ``` Full build log: [dev-util:lldb-18.0.0_pre20231206:20231206-163149.log](https://github.com/llvm/llvm-project/files/13588891/dev-util.lldb-18.0.0_pre20231206.20231206-163149.log) https://github.com/llvm/llvm-project/pull/70996 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix build on NetBSD (PR #74190)
https://github.com/mgorny approved this pull request. LGTM. Thanks! https://github.com/llvm/llvm-project/pull/74190 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix building on NetBSD 8.x (PR #74191)
https://github.com/mgorny approved this pull request. LGTM, though I don;t have an environment to test it. https://github.com/llvm/llvm-project/pull/74191 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] e5f0f1d - [lldb] [NetBSD] getValue => operator* for Optional migration
Author: Nikita Ronja Gillmann Date: 2023-05-07T06:12:19+02:00 New Revision: e5f0f1d3ee9589caec4e3859a4e57d6ece473dbe URL: https://github.com/llvm/llvm-project/commit/e5f0f1d3ee9589caec4e3859a4e57d6ece473dbe DIFF: https://github.com/llvm/llvm-project/commit/e5f0f1d3ee9589caec4e3859a4e57d6ece473dbe.diff LOG: [lldb] [NetBSD] getValue => operator* for Optional migration Differential Revision: https://reviews.llvm.org/D150032 Added: Modified: lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp Removed: diff --git a/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp b/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp index b8de5f0848836..13607bd261d40 100644 --- a/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp +++ b/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp @@ -409,7 +409,7 @@ NativeRegisterContextNetBSD_x86_64::ReadRegister(const RegisterInfo *reg_info, return error; } - RegSetKind set = opt_set.getValue(); + RegSetKind set = *opt_set; error = ReadRegisterSet(set); if (error.Fail()) return error; @@ -476,7 +476,7 @@ Status NativeRegisterContextNetBSD_x86_64::WriteRegister( return error; } - RegSetKind set = opt_set.getValue(); + RegSetKind set = *opt_set; uint64_t new_xstate_bv = 0; error = ReadRegisterSet(set); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] dfc2070 - [lldb] [utils] Fix linking lit-cpuid to LLVM dylib
Author: Michał Górny Date: 2022-12-26T19:03:25+01:00 New Revision: dfc20708bcdf7b4c4bea8595fc4ac8674634d5e6 URL: https://github.com/llvm/llvm-project/commit/dfc20708bcdf7b4c4bea8595fc4ac8674634d5e6 DIFF: https://github.com/llvm/llvm-project/commit/dfc20708bcdf7b4c4bea8595fc4ac8674634d5e6.diff LOG: [lldb] [utils] Fix linking lit-cpuid to LLVM dylib Use `LINK_COMPONENTS` instead of manual `target_link_libraries` to link lit-cpuid to LLVM components. This ensures that dylib is used along with `LLVM_LINK_LLVM_DYLIB` rather than linking to component libraries that may not be installed. This fixes build failure on Gentoo after a dep on TargetParser component was added in f09cf34d00625e57dea5317a3ac0412c07292148. Differential Revision: https://reviews.llvm.org/D140671 Added: Modified: lldb/utils/lit-cpuid/CMakeLists.txt Removed: diff --git a/lldb/utils/lit-cpuid/CMakeLists.txt b/lldb/utils/lit-cpuid/CMakeLists.txt index 630e81eaab09b..a151b986b551e 100644 --- a/lldb/utils/lit-cpuid/CMakeLists.txt +++ b/lldb/utils/lit-cpuid/CMakeLists.txt @@ -1,6 +1,9 @@ add_lldb_executable(lit-cpuid lit-cpuid.cpp + + LINK_COMPONENTS +Support +TargetParser ) -target_link_libraries(lit-cpuid PRIVATE LLVMSupport LLVMTargetParser) set_target_properties(lit-cpuid PROPERTIES FOLDER "lldb utils") ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] c899b24 - [lldb] [cmake] Fix another typo in third-party/unittest path
Author: Michał Górny Date: 2022-11-12T10:35:19+01:00 New Revision: c899b243f681fa75cb68144a4d599fdada764d78 URL: https://github.com/llvm/llvm-project/commit/c899b243f681fa75cb68144a4d599fdada764d78 DIFF: https://github.com/llvm/llvm-project/commit/c899b243f681fa75cb68144a4d599fdada764d78.diff LOG: [lldb] [cmake] Fix another typo in third-party/unittest path Added: Modified: lldb/cmake/modules/LLDBStandalone.cmake Removed: diff --git a/lldb/cmake/modules/LLDBStandalone.cmake b/lldb/cmake/modules/LLDBStandalone.cmake index 22a284adc222b..81304723f0f40 100644 --- a/lldb/cmake/modules/LLDBStandalone.cmake +++ b/lldb/cmake/modules/LLDBStandalone.cmake @@ -101,7 +101,7 @@ if(LLDB_INCLUDE_TESTS) # Build the gtest library needed for unittests, if we have LLVM sources # handy. if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest AND NOT TARGET llvm_gtest) -add_subdirectory(${LLVM_THIRD_PARTY_DIR}/utils/unittest third-party/unittest) +add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest third-party/unittest) endif() # LLVMTestingSupport library is needed for Process/gdb-remote. if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 2d2854c - [lldb] [cmake] Fix typo in unittest directory path
Author: Michał Górny Date: 2022-11-11T20:40:37+01:00 New Revision: 2d2854c7d5f9c1723e7ecbe7e8b8f9a2a78941a9 URL: https://github.com/llvm/llvm-project/commit/2d2854c7d5f9c1723e7ecbe7e8b8f9a2a78941a9 DIFF: https://github.com/llvm/llvm-project/commit/2d2854c7d5f9c1723e7ecbe7e8b8f9a2a78941a9.diff LOG: [lldb] [cmake] Fix typo in unittest directory path Fix a typo in a11cd0d94ed3cabf0998a0289aead05da94c86eb that resulted in additional "}" in unittest directory path, e.g.: CMake Error at cmake/modules/LLDBStandalone.cmake:104 (add_subdirectory): add_subdirectory given source "/var/tmp/portage/dev-util/lldb-16.0.0_pre2022/work/lldb/../third-party}/utils/unittest" which is not an existing directory. Call Stack (most recent call first): CMakeLists.txt:29 (include) Added: Modified: lldb/cmake/modules/LLDBStandalone.cmake Removed: diff --git a/lldb/cmake/modules/LLDBStandalone.cmake b/lldb/cmake/modules/LLDBStandalone.cmake index ce16f558012c5..22a284adc222b 100644 --- a/lldb/cmake/modules/LLDBStandalone.cmake +++ b/lldb/cmake/modules/LLDBStandalone.cmake @@ -101,7 +101,7 @@ if(LLDB_INCLUDE_TESTS) # Build the gtest library needed for unittests, if we have LLVM sources # handy. if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest AND NOT TARGET llvm_gtest) -add_subdirectory(${LLVM_THIRD_PARTY_DIR}}/utils/unittest third-party/unittest) +add_subdirectory(${LLVM_THIRD_PARTY_DIR}/utils/unittest third-party/unittest) endif() # LLVMTestingSupport library is needed for Process/gdb-remote. if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 88d7508 - Harmonize cmake_policy() across standalone builds of all projects
Author: Michał Górny Date: 2022-10-27T13:46:56+02:00 New Revision: 88d7508dc479210f07abccb17f0194b66264b125 URL: https://github.com/llvm/llvm-project/commit/88d7508dc479210f07abccb17f0194b66264b125 DIFF: https://github.com/llvm/llvm-project/commit/88d7508dc479210f07abccb17f0194b66264b125.diff LOG: Harmonize cmake_policy() across standalone builds of all projects Move `cmake_policy()` settings from `llvm/CMakeLists.txt` into a shared `cmake/modules/CMakePolicy.cmake`. Include it from all relevant projects that support standalone builds, in order to ensure that the policies are consistently set whether they are built in-tree or stand-alone. Differential Revision: https://reviews.llvm.org/D136572 Added: cmake/Modules/CMakePolicy.cmake Modified: clang/CMakeLists.txt flang/CMakeLists.txt lld/CMakeLists.txt lldb/CMakeLists.txt lldb/cmake/modules/LLDBStandalone.cmake llvm/CMakeLists.txt mlir/CMakeLists.txt Removed: diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 6f590c830b23d..fcd09c16bb57e 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.13.4) +include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) # If we are not building as a part of LLVM, build Clang as an # standalone project, using LLVM as an external library: diff --git a/cmake/Modules/CMakePolicy.cmake b/cmake/Modules/CMakePolicy.cmake new file mode 100644 index 0..0ec32ad8637f3 --- /dev/null +++ b/cmake/Modules/CMakePolicy.cmake @@ -0,0 +1,12 @@ +# CMake policy settings shared between LLVM projects + +# CMP0114: ExternalProject step targets fully adopt their steps. +# New in CMake 3.19: https://cmake.org/cmake/help/latest/policy/CMP0114.html +if(POLICY CMP0114) + cmake_policy(SET CMP0114 OLD) +endif() +# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()` +# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html +if(POLICY CMP0116) + cmake_policy(SET CMP0116 OLD) +endif() diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index 27cb22ba0e382..a938ab949481a 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.13.4) +include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) diff --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt index be4ea8540750e..964bc3fd8b175 100644 --- a/lld/CMakeLists.txt +++ b/lld/CMakeLists.txt @@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.13.4) +include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) # If we are not building as a part of LLVM, build LLD as an # standalone project, using LLVM as an external library: diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt index 12ba8a9d79e20..fad7b00dc624d 100644 --- a/lldb/CMakeLists.txt +++ b/lldb/CMakeLists.txt @@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.13.4) +include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) # Add path for custom modules. set(CMAKE_MODULE_PATH diff --git a/lldb/cmake/modules/LLDBStandalone.cmake b/lldb/cmake/modules/LLDBStandalone.cmake index 1a03c5a5ef749..3ce63f12eef39 100644 --- a/lldb/cmake/modules/LLDBStandalone.cmake +++ b/lldb/cmake/modules/LLDBStandalone.cmake @@ -1,9 +1,3 @@ -# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()` -# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html -if(POLICY CMP0116) - cmake_policy(SET CMP0116 OLD) -endif() - if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) endif() diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 5b493a7ebad55..5a81bd4598824 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1,17 +1,8 @@ # See docs/CMake.html for instructions about how to build LLVM with CMake. cmake_minimum_required(VERSION 3.13.4) - -# CMP0114: ExternalProject step targets fully adopt their steps. -# New in CMake 3.19: https://cmake.org/cmake/help/latest/policy/CMP0114.html -if(POLICY CMP0114) - cmake_policy(SET CMP0114 OLD) -endif() -# CMP0116: Ninja generators transform `DEPFILE`s from `add_custom_command()` -# New in CMake 3.20. https://cmake.org/cmake/help/latest/policy/CMP0116.html -if(POLICY CMP0116) - cmake_policy(SET CMP0116 OLD) -endif() +include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/CMakePolicy.cmake + NO_POLICY_SCOPE) set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt index 5b6650d182a56..33988682c8231 100644 --- a/mlir/CMakeLists.txt +++ b/mlir/CMakeLists.txt @@ -1,4 +1,7 @@ # MLIR project. +cmake_minimum_required(VERSION 3.13.4)
[Lldb-commits] [lldb] 52f3985 - [lldb] Include gtest in standalone build only if LLDB_INCLUDE_TESTS
Author: Michał Górny Date: 2022-10-24T15:51:43+02:00 New Revision: 52f39853abd46495a6d636c4b035e1b92cf4b833 URL: https://github.com/llvm/llvm-project/commit/52f39853abd46495a6d636c4b035e1b92cf4b833 DIFF: https://github.com/llvm/llvm-project/commit/52f39853abd46495a6d636c4b035e1b92cf4b833.diff LOG: [lldb] Include gtest in standalone build only if LLDB_INCLUDE_TESTS Build gtest targets when building standalone only if LLDB_INCLUDE_TESTS is true. Prior to this change, they were built whenever LLVM_MAIN_SRC_DIR was available, independently whether tests themselves would be run. Differential Revision: https://reviews.llvm.org/D136551 Added: Modified: lldb/CMakeLists.txt lldb/cmake/modules/LLDBStandalone.cmake Removed: diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt index 88a8f0a651399..12ba8a9d79e20 100644 --- a/lldb/CMakeLists.txt +++ b/lldb/CMakeLists.txt @@ -17,6 +17,8 @@ endif() # Must go below project(..) include(GNUInstallDirs) +option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS}) + if(LLDB_BUILT_STANDALONE) include(LLDBStandalone) @@ -129,7 +131,6 @@ if (NOT TARGET llvm_gtest) set(LLDB_INCLUDE_UNITTESTS OFF) endif() -option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS}) if(LLDB_INCLUDE_TESTS) add_subdirectory(test) if (LLDB_INCLUDE_UNITTESTS) diff --git a/lldb/cmake/modules/LLDBStandalone.cmake b/lldb/cmake/modules/LLDBStandalone.cmake index 98a52969ba30f..1a03c5a5ef749 100644 --- a/lldb/cmake/modules/LLDBStandalone.cmake +++ b/lldb/cmake/modules/LLDBStandalone.cmake @@ -103,16 +103,18 @@ include_directories( "${LLVM_INCLUDE_DIRS}" "${CLANG_INCLUDE_DIRS}") -# Build the gtest library needed for unittests, if we have LLVM sources -# handy. -if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest AND NOT TARGET llvm_gtest) - add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/unittest utils/unittest) -endif() -# LLVMTestingSupport library is needed for Process/gdb-remote. -if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support -AND NOT TARGET LLVMTestingSupport) - add_subdirectory(${LLVM_MAIN_SRC_DIR}/lib/Testing/Support -lib/Testing/Support) +if(LLDB_INCLUDE_TESTS) + # Build the gtest library needed for unittests, if we have LLVM sources + # handy. + if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest AND NOT TARGET llvm_gtest) +add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/unittest utils/unittest) + endif() + # LLVMTestingSupport library is needed for Process/gdb-remote. + if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support + AND NOT TARGET LLVMTestingSupport) +add_subdirectory(${LLVM_MAIN_SRC_DIR}/lib/Testing/Support + lib/Testing/Support) + endif() endif() option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] d152393 - [lldb] Add LLVM include dirs prior to gtest target in standalone build
Author: Michał Górny Date: 2022-10-24T12:18:14+02:00 New Revision: d15239388cca8a5031119b4660e456c26ca5f379 URL: https://github.com/llvm/llvm-project/commit/d15239388cca8a5031119b4660e456c26ca5f379 DIFF: https://github.com/llvm/llvm-project/commit/d15239388cca8a5031119b4660e456c26ca5f379.diff LOG: [lldb] Add LLVM include dirs prior to gtest target in standalone build Move include_directories() declaration before gtest targets are created in standalone build. This fixes build failure due to gtest targets being unable to find LLVM headers, e.g.: /var/tmp/portage/dev-util/lldb-16.0.0_pre20221023/work/llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h:43:10: fatal error: llvm/ADT/Optional.h: No such file or directory Differential Revision: https://reviews.llvm.org/D136552 Added: Modified: lldb/cmake/modules/LLDBStandalone.cmake Removed: diff --git a/lldb/cmake/modules/LLDBStandalone.cmake b/lldb/cmake/modules/LLDBStandalone.cmake index 9cd3f1e8186ba..98a52969ba30f 100644 --- a/lldb/cmake/modules/LLDBStandalone.cmake +++ b/lldb/cmake/modules/LLDBStandalone.cmake @@ -97,6 +97,12 @@ include(LLVMDistributionSupport) set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") set(LLVM_INCLUDE_TESTS ON CACHE INTERNAL "") +set(CMAKE_INCLUDE_CURRENT_DIR ON) +include_directories( + "${CMAKE_BINARY_DIR}/include" + "${LLVM_INCLUDE_DIRS}" + "${CLANG_INCLUDE_DIRS}") + # Build the gtest library needed for unittests, if we have LLVM sources # handy. if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest AND NOT TARGET llvm_gtest) @@ -117,12 +123,6 @@ endif() set_target_properties(clang-tablegen-targets PROPERTIES FOLDER "lldb misc") set_target_properties(intrinsics_gen PROPERTIES FOLDER "lldb misc") -set(CMAKE_INCLUDE_CURRENT_DIR ON) -include_directories( - "${CMAKE_BINARY_DIR}/include" - "${LLVM_INCLUDE_DIRS}" - "${CLANG_INCLUDE_DIRS}") - if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) endif() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] e8ee0f1 - [lldb] [MainLoopPosix] Fix crash upon adding lots of pending callbacks
Author: Michał Górny Date: 2022-10-17T17:48:44+02:00 New Revision: e8ee0f121dbc2dc20a9de326531c4d4d061a20d8 URL: https://github.com/llvm/llvm-project/commit/e8ee0f121dbc2dc20a9de326531c4d4d061a20d8 DIFF: https://github.com/llvm/llvm-project/commit/e8ee0f121dbc2dc20a9de326531c4d4d061a20d8.diff LOG: [lldb] [MainLoopPosix] Fix crash upon adding lots of pending callbacks If lots of pending callbacks are added while the main loop has exited already, the trigger pipe buffer fills in, causing the write to fail and the related assertion to fail. To avoid this, add a boolean member indicating whether the callbacks have been triggered already. If the trigger was done, avoid writing to the pipe until loops proceeds to run them and resets the variable. Besides fixing the issue, this also avoids writing to the pipe multiple times if callbacks are added faster than the loop is able to process them. Previously, this would lead to the loop performing multiple read iterations from pipe unnecessarily. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D135516 Added: Modified: lldb/include/lldb/Host/posix/MainLoopPosix.h lldb/source/Host/posix/MainLoopPosix.cpp lldb/unittests/Host/MainLoopTest.cpp Removed: diff --git a/lldb/include/lldb/Host/posix/MainLoopPosix.h b/lldb/include/lldb/Host/posix/MainLoopPosix.h index 18185c3c5ee78..07497b7b8c259 100644 --- a/lldb/include/lldb/Host/posix/MainLoopPosix.h +++ b/lldb/include/lldb/Host/posix/MainLoopPosix.h @@ -13,6 +13,7 @@ #include "lldb/Host/MainLoopBase.h" #include "lldb/Host/Pipe.h" #include "llvm/ADT/DenseMap.h" +#include #include #include #include @@ -87,6 +88,7 @@ class MainLoopPosix : public MainLoopBase { llvm::DenseMap m_read_fds; llvm::DenseMap m_signals; Pipe m_trigger_pipe; + std::atomic m_triggering; #if HAVE_SYS_EVENT_H int m_kqueue; #endif diff --git a/lldb/source/Host/posix/MainLoopPosix.cpp b/lldb/source/Host/posix/MainLoopPosix.cpp index 37d339d8bc779..b185c3d3b7076 100644 --- a/lldb/source/Host/posix/MainLoopPosix.cpp +++ b/lldb/source/Host/posix/MainLoopPosix.cpp @@ -222,7 +222,7 @@ void MainLoopPosix::RunImpl::ProcessEvents() { } #endif -MainLoopPosix::MainLoopPosix() { +MainLoopPosix::MainLoopPosix() : m_triggering(false) { Status error = m_trigger_pipe.CreateNew(/*child_process_inherit=*/false); assert(error.Success()); const int trigger_pipe_fd = m_trigger_pipe.GetReadFileDescriptor(); @@ -371,6 +371,7 @@ Status MainLoopPosix::Run() { impl.ProcessEvents(); +m_triggering = false; ProcessPendingCallbacks(); } return Status(); @@ -395,6 +396,9 @@ void MainLoopPosix::ProcessSignal(int signo) { } void MainLoopPosix::TriggerPendingCallbacks() { + if (m_triggering.exchange(true)) +return; + char c = '.'; size_t bytes_written; Status error = m_trigger_pipe.Write(, 1, bytes_written); diff --git a/lldb/unittests/Host/MainLoopTest.cpp b/lldb/unittests/Host/MainLoopTest.cpp index 00e85514463fe..b1857fec3c49e 100644 --- a/lldb/unittests/Host/MainLoopTest.cpp +++ b/lldb/unittests/Host/MainLoopTest.cpp @@ -171,6 +171,17 @@ TEST_F(MainLoopTest, PendingCallbackTrigger) { ASSERT_TRUE(callback2_called); } +// Regression test for assertion failure if a lot of callbacks end up +// being queued after loop exits. +TEST_F(MainLoopTest, PendingCallbackAfterLoopExited) { + MainLoop loop; + Status error; + ASSERT_TRUE(loop.Run().Success()); + // Try to fill the pipe buffer in. + for (int i = 0; i < 65536; ++i) +loop.AddPendingCallback([&](MainLoopBase ) {}); +} + #ifdef LLVM_ON_UNIX TEST_F(MainLoopTest, DetectsEOF) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] b6c24c1 - [lldb] [gdb-remote] Move ReadPacketWithOutputSupport() to client
Author: Michał Górny Date: 2022-10-03T18:42:49+02:00 New Revision: b6c24c161900a035f5ea7193f4816b6d192d6ac8 URL: https://github.com/llvm/llvm-project/commit/b6c24c161900a035f5ea7193f4816b6d192d6ac8 DIFF: https://github.com/llvm/llvm-project/commit/b6c24c161900a035f5ea7193f4816b6d192d6ac8.diff LOG: [lldb] [gdb-remote] Move ReadPacketWithOutputSupport() to client Move ReadPacketWithOutputSupport() from GDBRemoteCommunication to GDBRemoteClientBase. This function is client-specific and moving it there simplifies followup patches that split communication into separate thread. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D135028 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp index ae85dbc68336d..394b62559da76 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp @@ -194,6 +194,23 @@ GDBRemoteClientBase::SendPacketAndWaitForResponse( return SendPacketAndWaitForResponseNoLock(payload, response); } +GDBRemoteCommunication::PacketResult +GDBRemoteClientBase::ReadPacketWithOutputSupport( +StringExtractorGDBRemote , Timeout timeout, +bool sync_on_timeout, +llvm::function_ref output_callback) { + auto result = ReadPacket(response, timeout, sync_on_timeout); + while (result == PacketResult::Success && response.IsNormalResponse() && + response.PeekChar() == 'O') { +response.GetChar(); +std::string output; +if (response.GetHexByteString(output)) + output_callback(output); +result = ReadPacket(response, timeout, sync_on_timeout); + } + return result; +} + GDBRemoteCommunication::PacketResult GDBRemoteClientBase::SendPacketAndReceiveResponseWithOutputSupport( llvm::StringRef payload, StringExtractorGDBRemote , diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h index 4dd67a2b11f7e..b47fee76a2ab5 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h @@ -58,6 +58,11 @@ class GDBRemoteClientBase : public GDBRemoteCommunication, public Broadcaster { llvm::StringRef payload, StringExtractorGDBRemote , std::chrono::seconds interrupt_timeout = std::chrono::seconds(0)); + PacketResult ReadPacketWithOutputSupport( + StringExtractorGDBRemote , Timeout timeout, + bool sync_on_timeout, + llvm::function_ref output_callback); + PacketResult SendPacketAndReceiveResponseWithOutputSupport( llvm::StringRef payload, StringExtractorGDBRemote , std::chrono::seconds interrupt_timeout, diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index b67cd7efd8846..7daf003fec7ba 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -220,23 +220,6 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunication::GetAck() { return result; } -GDBRemoteCommunication::PacketResult -GDBRemoteCommunication::ReadPacketWithOutputSupport( -StringExtractorGDBRemote , Timeout timeout, -bool sync_on_timeout, -llvm::function_ref output_callback) { - auto result = ReadPacket(response, timeout, sync_on_timeout); - while (result == PacketResult::Success && response.IsNormalResponse() && - response.PeekChar() == 'O') { -response.GetChar(); -std::string output; -if (response.GetHexByteString(output)) - output_callback(output); -result = ReadPacket(response, timeout, sync_on_timeout); - } - return result; -} - GDBRemoteCommunication::PacketResult GDBRemoteCommunication::ReadPacket(StringExtractorGDBRemote , Timeout timeout, diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h index 9e17d6cc65238..4e59bd5ec8be6 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h @@ -190,11 +190,6 @@ class GDBRemoteCommunication : public Communication { PacketResult ReadPacket(StringExtractorGDBRemote , Timeout timeout, bool sync_on_timeout); - PacketResult ReadPacketWithOutputSupport( -
[Lldb-commits] [lldb] bdb4468 - [gdb-remote] Move broadcasting logic down to GDBRemoteClientBase
Author: Michał Górny Date: 2022-09-09T17:13:08+02:00 New Revision: bdb4468d39496088fc05d8c5575647fac9c8062a URL: https://github.com/llvm/llvm-project/commit/bdb4468d39496088fc05d8c5575647fac9c8062a DIFF: https://github.com/llvm/llvm-project/commit/bdb4468d39496088fc05d8c5575647fac9c8062a.diff LOG: [gdb-remote] Move broadcasting logic down to GDBRemoteClientBase Move the broadcasting support from GDBRemoteCommunication to GDBRemoteClientBase since this is where it is actually used. Remove GDBRemoteCommunication and subclass constructor arguments left over after Communication cleanup. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D133427 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp index e3a3cfc4f23e..ae85dbc68336 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp @@ -31,10 +31,9 @@ static const seconds kWakeupInterval(5); GDBRemoteClientBase::ContinueDelegate::~ContinueDelegate() = default; -GDBRemoteClientBase::GDBRemoteClientBase(const char *comm_name, - const char *listener_name) -: GDBRemoteCommunication(comm_name, listener_name), m_async_count(0), - m_is_running(false), m_should_stop(false) {} +GDBRemoteClientBase::GDBRemoteClientBase(const char *comm_name) +: GDBRemoteCommunication(), Broadcaster(nullptr, comm_name), + m_async_count(0), m_is_running(false), m_should_stop(false) {} StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse( ContinueDelegate , const UnixSignals , diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h index 43a5313eae6a..4dd67a2b11f7 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h @@ -16,8 +16,12 @@ namespace lldb_private { namespace process_gdb_remote { -class GDBRemoteClientBase : public GDBRemoteCommunication { +class GDBRemoteClientBase : public GDBRemoteCommunication, public Broadcaster { public: + enum { +eBroadcastBitRunPacketSent = (1u << 0), + }; + struct ContinueDelegate { virtual ~ContinueDelegate(); virtual void HandleAsyncStdout(llvm::StringRef out) = 0; @@ -31,7 +35,7 @@ class GDBRemoteClientBase : public GDBRemoteCommunication { virtual void HandleAsyncStructuredDataPacket(llvm::StringRef data) = 0; }; - GDBRemoteClientBase(const char *comm_name, const char *listener_name); + GDBRemoteClientBase(const char *comm_name); bool SendAsyncSignal(int signo, std::chrono::seconds interrupt_timeout); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 33e041bb6e3e..b0cec915bc34 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -58,9 +58,8 @@ using namespace lldb_private; using namespace lldb_private::process_gdb_remote; // GDBRemoteCommunication constructor -GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name, - const char *listener_name) -: Communication(), Broadcaster(nullptr, comm_name), +GDBRemoteCommunication::GDBRemoteCommunication() +: Communication(), #ifdef LLDB_CONFIGURATION_DEBUG m_packet_timeout(1000), #else diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
[Lldb-commits] [lldb] 9823d42 - [lldb] [Core] Split read thread support into ThreadedCommunication
Author: Michał Górny Date: 2022-09-06T13:09:42+02:00 New Revision: 9823d42557eb1da3ecf2f771ea2cbc84a988ef92 URL: https://github.com/llvm/llvm-project/commit/9823d42557eb1da3ecf2f771ea2cbc84a988ef92 DIFF: https://github.com/llvm/llvm-project/commit/9823d42557eb1da3ecf2f771ea2cbc84a988ef92.diff LOG: [lldb] [Core] Split read thread support into ThreadedCommunication Split the read thread support from Communication into a dedicated ThreadedCommunication subclass. The read thread support is used only by a subset of Communication consumers, and it adds a lot of complexity to the base class. Furthermore, having a dedicated subclass makes it clear whether a particular consumer needs to account for the possibility of read thread being running or not. The modules currently calling `StartReadThread()` are updated to use `ThreadedCommunication`. The remaining modules use the simplified `Communication` class. `SBCommunication` is changed to use `ThreadedCommunication` in order to avoid changing the public API. `CommunicationKDP` is updated in order to (hopefully) compile with the new code. However, I do not have a Darwin box to test it, so I've limited the changes to the bare minimum. `GDBRemoteCommunication` is updated to become a `Broadcaster` directly. Since it does not inherit from `ThreadedCommunication`, its event support no longer collides with the one used for read thread and can be implemented cleanly. The support for `eBroadcastBitReadThreadDidExit` is removed from the code -- since the read thread was not used, this event was never reported. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D133251 Added: lldb/include/lldb/Core/ThreadedCommunication.h lldb/source/Core/ThreadedCommunication.cpp Modified: lldb/include/lldb/API/SBCommunication.h lldb/include/lldb/Core/Communication.h lldb/include/lldb/Interpreter/ScriptInterpreter.h lldb/include/lldb/Target/Process.h lldb/include/lldb/lldb-forward.h lldb/source/API/SBCommunication.cpp lldb/source/Core/CMakeLists.txt lldb/source/Core/Communication.cpp lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/unittests/Core/CommunicationTest.cpp Removed: diff --git a/lldb/include/lldb/API/SBCommunication.h b/lldb/include/lldb/API/SBCommunication.h index e407d859d8850..fa8c88acd3fb8 100644 --- a/lldb/include/lldb/API/SBCommunication.h +++ b/lldb/include/lldb/API/SBCommunication.h @@ -75,7 +75,7 @@ class LLDB_API SBCommunication { SBCommunication(const SBCommunication &) = delete; const SBCommunication =(const SBCommunication &) = delete; - lldb_private::Communication *m_opaque = nullptr; + lldb_private::ThreadedCommunication *m_opaque = nullptr; bool m_opaque_owned = false; }; diff --git a/lldb/include/lldb/Core/Communication.h b/lldb/include/lldb/Core/Communication.h index c07b06a6c2509..a0151527fe5de 100644 --- a/lldb/include/lldb/Core/Communication.h +++ b/lldb/include/lldb/Core/Communication.h @@ -9,22 +9,15 @@ #ifndef LLDB_CORE_COMMUNICATION_H #define LLDB_CORE_COMMUNICATION_H -#include "lldb/Host/HostThread.h" -#include "lldb/Utility/Broadcaster.h" #include "lldb/Utility/Timeout.h" #include "lldb/lldb-defines.h" #include "lldb/lldb-enumerations.h" #include "lldb/lldb-forward.h" #include "lldb/lldb-types.h" -#include #include -#include #include -#include -#include - namespace lldb_private { class Connection; class ConstString; @@ -38,90 +31,22 @@ class Status; /// approach has a couple of advantages: it allows a single instance of this /// class to be used even though its connection can change. Connections could /// negotiate for diff erent connections based on abilities like starting with -/// Bluetooth and negotiating up to WiFi if available. It also allows this -/// class to be subclassed by any interfaces that don't want to give bytes but -/// want to validate and give out packets. This can be done by overriding: -/// -/// AppendBytesToCache (const uint8_t *src, size_t src_len, bool broadcast); -/// -/// Communication inherits from Broadcaster which means it can be used in -/// conjunction with Listener to wait for multiple broadcaster objects and -/// multiple events from each of those objects. Communication defines a set of -/// pre-defined event bits (see enumerations definitions that start with -/// "eBroadcastBit" below). -/// -/// There are two modes in which communications can occur:
[Lldb-commits] [lldb] 39e0a87 - [lldb] [Core] Pass error/status from Communication::ReadThread()
Author: Michał Górny Date: 2022-09-01T14:16:38+02:00 New Revision: 39e0a87c26e0d2b7498186a446dda4ec3d9b709d URL: https://github.com/llvm/llvm-project/commit/39e0a87c26e0d2b7498186a446dda4ec3d9b709d DIFF: https://github.com/llvm/llvm-project/commit/39e0a87c26e0d2b7498186a446dda4ec3d9b709d.diff LOG: [lldb] [Core] Pass error/status from Communication::ReadThread() Ensure that the ConnectionStatus and Status from Communication::ReadThread() is correctly passed to ::Read() in order to fix further discrepancies between ::Read() calls in non-threaded and threaded modes. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D132577 Added: Modified: lldb/include/lldb/Core/Communication.h lldb/source/Core/Communication.cpp lldb/unittests/Core/CommunicationTest.cpp Removed: diff --git a/lldb/include/lldb/Core/Communication.h b/lldb/include/lldb/Core/Communication.h index 44b3a16a05269..c07b06a6c2509 100644 --- a/lldb/include/lldb/Core/Communication.h +++ b/lldb/include/lldb/Core/Communication.h @@ -324,6 +324,9 @@ class Communication : public Broadcaster { m_bytes; ///< A buffer to cache bytes read in the ReadThread function. std::recursive_mutex m_bytes_mutex; ///< A mutex to protect multi-threaded ///access to the cached bytes. + lldb::ConnectionStatus m_pass_status; ///< Connection status passthrough +///from read thread. + Status m_pass_error; ///< Error passthrough from read thread. std::mutex m_write_mutex; ///< Don't let multiple threads write at the same time... std::mutex m_synchronize_mutex; diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp index 56f0990d8c7f7..3606d92a9d4e0 100644 --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -162,14 +162,10 @@ size_t Communication::Read(void *dst, size_t dst_len, if (event_type & eBroadcastBitReadThreadDidExit) { // If the thread exited of its own accord, it either means it -// hit an end-of-file condition or lost connection -// (we verified that we had an connection above). -if (!m_connection_sp) { - if (error_ptr) -error_ptr->SetErrorString("Lost connection."); - status = eConnectionStatusLostConnection; -} else - status = eConnectionStatusEndOfFile; +// hit an end-of-file condition or an error. +status = m_pass_status; +if (error_ptr) + *error_ptr = std::move(m_pass_error); if (GetCloseOnEOF()) Disconnect(nullptr); @@ -384,7 +380,8 @@ lldb::thread_result_t Communication::ReadThread() { break; } } - log = GetLog(LLDBLog::Communication); + m_pass_status = status; + m_pass_error = std::move(error); LLDB_LOG(log, "Communication({0}) thread exiting...", this); // Handle threads wishing to synchronize with us. diff --git a/lldb/unittests/Core/CommunicationTest.cpp b/lldb/unittests/Core/CommunicationTest.cpp index 5cb1d4a3bbbf0..a6da6302e5e14 100644 --- a/lldb/unittests/Core/CommunicationTest.cpp +++ b/lldb/unittests/Core/CommunicationTest.cpp @@ -15,6 +15,7 @@ #include "TestingSupport/Host/SocketTestUtilities.h" #include "TestingSupport/SubsystemRAII.h" +#include #include #if LLDB_ENABLE_POSIX @@ -78,9 +79,31 @@ static void CommunicationReadTest(bool use_read_thread) { EXPECT_EQ(status, lldb::eConnectionStatusEndOfFile); EXPECT_THAT_ERROR(error.ToError(), llvm::Succeeded()); - // JoinReadThread() should just return immediately since there was no read + // JoinReadThread() should just return immediately if there was no read // thread started. EXPECT_TRUE(comm.JoinReadThread()); + + // Test using Communication that is disconnected. + ASSERT_EQ(comm.Disconnect(), lldb::eConnectionStatusSuccess); + if (use_read_thread) +ASSERT_TRUE(comm.StartReadThread()); + error.Clear(); + EXPECT_EQ( + comm.Read(buf, sizeof(buf), std::chrono::seconds(5), status, ), 0U); + EXPECT_EQ(status, lldb::eConnectionStatusLostConnection); + EXPECT_THAT_ERROR(error.ToError(), llvm::Failed()); + EXPECT_TRUE(comm.JoinReadThread()); + + // Test using Communication without a connection. + comm.SetConnection(nullptr); + if (use_read_thread) +ASSERT_TRUE(comm.StartReadThread()); + error.Clear(); + EXPECT_EQ( + comm.Read(buf, sizeof(buf), std::chrono::seconds(5), status, ), 0U); + EXPECT_EQ(status, lldb::eConnectionStatusNoConnection); + EXPECT_THAT_ERROR(error.ToError(), llvm::Failed()); + EXPECT_TRUE(comm.JoinReadThread()); } TEST_F(CommunicationTest, Read) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 03b8f79 - [lldb] [gdb-remote] Use Communication::WriteAll() over Write()
Author: Michał Górny Date: 2022-08-23T15:49:16+02:00 New Revision: 03b8f79048bfc32ade0404df3d3931266a06dc92 URL: https://github.com/llvm/llvm-project/commit/03b8f79048bfc32ade0404df3d3931266a06dc92 DIFF: https://github.com/llvm/llvm-project/commit/03b8f79048bfc32ade0404df3d3931266a06dc92.diff LOG: [lldb] [gdb-remote] Use Communication::WriteAll() over Write() Replace the uses of Communication::Write() with WriteAll() to avoid partial writes. None of the call sites actually accounted for that possibility and even if it is unlikely to actually happen, there doesn't seem to be any real harm from using WriteAll() instead. Ideally, we'd remove Write() from the public API. However, that would change the API of SBCommunication. The alternative would be to alias it to WriteAll(). Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D132395 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 34753d5f8128a..bc9ccad29afb1 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -2441,7 +2441,7 @@ GDBRemoteCommunicationServerLLGS::Handle_I(StringExtractorGDBRemote ) { // remote host ConnectionStatus status; Status error; -m_stdio_communication.Write(tmp, read, status, ); +m_stdio_communication.WriteAll(tmp, read, status, ); if (error.Fail()) { return SendErrorResponse(0x15); } diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index fbc7ab9180e77..37272d3afabd3 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -2880,7 +2880,7 @@ size_t ProcessGDBRemote::PutSTDIN(const char *src, size_t src_len, Status ) { if (m_stdio_communication.IsConnected()) { ConnectionStatus status; -m_stdio_communication.Write(src, src_len, status, nullptr); +m_stdio_communication.WriteAll(src, src_len, status, nullptr); } else if (m_stdin_forward) { m_gdb_comm.SendStdinNotification(src, src_len); } diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp index 4289a8393808f..7b17ec98a5cb4 100644 --- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp +++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp @@ -39,7 +39,7 @@ class GDBRemoteCommunicationTest : public GDBRemoteTest { bool Write(llvm::StringRef packet) { ConnectionStatus status; -return server.Write(packet.data(), packet.size(), status, nullptr) == +return server.WriteAll(packet.data(), packet.size(), status, nullptr) == packet.size(); } }; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] d92f49f - Reland "[lldb] [test] Disable new CommunicationTests on Windows"
Author: Michał Górny Date: 2022-08-20T08:32:55+02:00 New Revision: d92f49fc4b22a738bd39e4588543b0a23037bd69 URL: https://github.com/llvm/llvm-project/commit/d92f49fc4b22a738bd39e4588543b0a23037bd69 DIFF: https://github.com/llvm/llvm-project/commit/d92f49fc4b22a738bd39e4588543b0a23037bd69.diff LOG: Reland "[lldb] [test] Disable new CommunicationTests on Windows" This change was wrongly reverted and re-broke the Windows buildbot. Sponsored by: The FreeBSD Foundation Added: Modified: lldb/unittests/Core/CommunicationTest.cpp Removed: diff --git a/lldb/unittests/Core/CommunicationTest.cpp b/lldb/unittests/Core/CommunicationTest.cpp index 024684a486c2d..13ebfae772f47 100644 --- a/lldb/unittests/Core/CommunicationTest.cpp +++ b/lldb/unittests/Core/CommunicationTest.cpp @@ -21,6 +21,7 @@ using namespace lldb_private; +#ifndef _WIN32 static void CommunicationReadTest(bool use_read_thread) { Pipe pipe; ASSERT_THAT_ERROR(pipe.CreateNew(/*child_process_inherit=*/false).ToError(), @@ -87,7 +88,6 @@ TEST(CommunicationTest, ReadThread) { CommunicationReadTest(/*use_thread=*/true); } -#ifndef _WIN32 TEST(CommunicationTest, SynchronizeWhileClosing) { // Set up a communication object reading from a pipe. Pipe pipe; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 2f50883 - [lldb] [gdb-remote] Include PID in vCont packets if multiprocess
Author: Michał Górny Date: 2022-08-20T08:21:32+02:00 New Revision: 2f50883c132879395c2cb45c458a4ec132309b32 URL: https://github.com/llvm/llvm-project/commit/2f50883c132879395c2cb45c458a4ec132309b32 DIFF: https://github.com/llvm/llvm-project/commit/2f50883c132879395c2cb45c458a4ec132309b32.diff LOG: [lldb] [gdb-remote] Include PID in vCont packets if multiprocess Try to always send vCont packets and include the PID in them if running multiprocess. This is necessary to ensure that with the upcoming full multiprocess support always resumes the correct process without having to resort to the legacy Hc packets. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D131758 Added: lldb/test/API/functionalities/gdb_remote_client/TestContinue.py Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 29417b35fde3..11d0fec1926a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -181,6 +181,12 @@ bool GDBRemoteCommunicationClient::GetQXferSigInfoReadSupported() { return m_supports_qXfer_siginfo_read == eLazyBoolYes; } +bool GDBRemoteCommunicationClient::GetMultiprocessSupported() { + if (m_supports_memory_tagging == eLazyBoolCalculate) +GetRemoteQSupported(); + return m_supports_multiprocess == eLazyBoolYes; +} + uint64_t GDBRemoteCommunicationClient::GetRemoteMaxPacketSize() { if (m_max_packet_size == 0) { GetRemoteQSupported(); @@ -1514,7 +1520,7 @@ Status GDBRemoteCommunicationClient::Detach(bool keep_stopped, } } - if (m_supports_multiprocess) { + if (GetMultiprocessSupported()) { // Some servers (e.g. qemu) require specifying the PID even if only a single // process is running. if (pid == LLDB_INVALID_PROCESS_ID) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index 3a62747603f6..4e89ade772ad 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -339,6 +339,8 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase { bool GetQXferSigInfoReadSupported(); + bool GetMultiprocessSupported(); + LazyBool SupportsAllocDeallocMemory() // const { // Uncomment this to have lldb pretend the debug server doesn't respond to diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 30fb27932d19..fbc7ab9180e7 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1186,11 +1186,18 @@ Status ProcessGDBRemote::DoResume() { StreamString continue_packet; bool continue_packet_error = false; if (m_gdb_comm.HasAnyVContSupport()) { + std::string pid_prefix; + if (m_gdb_comm.GetMultiprocessSupported()) +pid_prefix = llvm::formatv("p{0:x-}.", GetID()); + if (m_continue_c_tids.size() == num_threads || (m_continue_c_tids.empty() && m_continue_C_tids.empty() && m_continue_s_tids.empty() && m_continue_S_tids.empty())) { -// All threads are continuing, just send a "c" packet -continue_packet.PutCString("c"); +// All threads are continuing +if (m_gdb_comm.GetMultiprocessSupported()) + continue_packet.Format("vCont;c:{0}-1", pid_prefix); +else + continue_packet.PutCString("c"); } else { continue_packet.PutCString("vCont"); @@ -1200,7 +1207,7 @@ Status ProcessGDBRemote::DoResume() { t_pos = m_continue_c_tids.begin(), t_end = m_continue_c_tids.end(); t_pos != t_end; ++t_pos) - continue_packet.Printf(";c:%4.4" PRIx64, *t_pos); + continue_packet.Format(";c:{0}{1:x-}", pid_prefix, *t_pos); } else continue_packet_error = true; } @@ -1211,8 +1218,8 @@ Status ProcessGDBRemote::DoResume() { s_pos = m_continue_C_tids.begin(), s_end = m_continue_C_tids.end(); s_pos != s_end; ++s_pos) - continue_packet.Printf(";C%2.2x:%4.4" PRIx64, s_pos->second, - s_pos->first); + continue_packet.Format(";C{0:x-2}:{1}{2:x-}", s_pos->second, +
[Lldb-commits] [lldb] d38985a - [lldb] [test] Disable new CommunicationTests on Windows
Author: Michał Górny Date: 2022-08-19T16:23:39+02:00 New Revision: d38985a36be8b0165787f8893b3d2b0f831d1e83 URL: https://github.com/llvm/llvm-project/commit/d38985a36be8b0165787f8893b3d2b0f831d1e83 DIFF: https://github.com/llvm/llvm-project/commit/d38985a36be8b0165787f8893b3d2b0f831d1e83.diff LOG: [lldb] [test] Disable new CommunicationTests on Windows Sponsored by: The FreeBSD Foundation Added: Modified: lldb/unittests/Core/CommunicationTest.cpp Removed: diff --git a/lldb/unittests/Core/CommunicationTest.cpp b/lldb/unittests/Core/CommunicationTest.cpp index 024684a486c2d..13ebfae772f47 100644 --- a/lldb/unittests/Core/CommunicationTest.cpp +++ b/lldb/unittests/Core/CommunicationTest.cpp @@ -21,6 +21,7 @@ using namespace lldb_private; +#ifndef _WIN32 static void CommunicationReadTest(bool use_read_thread) { Pipe pipe; ASSERT_THAT_ERROR(pipe.CreateNew(/*child_process_inherit=*/false).ToError(), @@ -87,7 +88,6 @@ TEST(CommunicationTest, ReadThread) { CommunicationReadTest(/*use_thread=*/true); } -#ifndef _WIN32 TEST(CommunicationTest, SynchronizeWhileClosing) { // Set up a communication object reading from a pipe. Pipe pipe; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 7aadeca - [lldb] [test] Add synchronization to TestContinue
Author: Michał Górny Date: 2022-08-19T15:49:35+02:00 New Revision: 7aadecae404b8d47aabdd874e9018a76fd4d1ffa URL: https://github.com/llvm/llvm-project/commit/7aadecae404b8d47aabdd874e9018a76fd4d1ffa DIFF: https://github.com/llvm/llvm-project/commit/7aadecae404b8d47aabdd874e9018a76fd4d1ffa.diff LOG: [lldb] [test] Add synchronization to TestContinue Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/functionalities/gdb_remote_client/TestContinue.py Removed: diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py b/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py index f0f0df81d321d..8d26cfbfdcc4e 100644 --- a/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py @@ -38,6 +38,8 @@ def qfThreadInfo(self): self.runCmd("platform select remote-linux") target = self.createTarget("a.yaml") process = self.connect(target) +lldbutil.expect_state_changes(self, self.dbg.GetListener(), process, + [lldb.eStateExited]) self.assertPacketLogContains(["vCont;C13:401"]) def test_continue_no_vCont(self): @@ -55,6 +57,8 @@ def other(self, packet): self.runCmd("platform select remote-linux") target = self.createTarget("a.yaml") process = self.connect(target) +lldbutil.expect_state_changes(self, self.dbg.GetListener(), process, + [lldb.eStateExited]) self.assertPacketLogContains(["Hc401", "C13"]) def test_continue_multiprocess(self): @@ -65,4 +69,6 @@ class MyResponder(self.BaseResponder): self.runCmd("platform select remote-linux") target = self.createTarget("a.yaml") process = self.connect(target) +lldbutil.expect_state_changes(self, self.dbg.GetListener(), process, + [lldb.eStateExited]) self.assertPacketLogContains(["vCont;C13:p400.401"]) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] d6e1e01 - [lldb] [Core] Harmonize Communication::Read() returns w/ thread
Author: Michał Górny Date: 2022-08-19T15:36:03+02:00 New Revision: d6e1e01da949c8cb4b869cee1953cf19a6d072c0 URL: https://github.com/llvm/llvm-project/commit/d6e1e01da949c8cb4b869cee1953cf19a6d072c0 DIFF: https://github.com/llvm/llvm-project/commit/d6e1e01da949c8cb4b869cee1953cf19a6d072c0.diff LOG: [lldb] [Core] Harmonize Communication::Read() returns w/ thread Harmonize the status and error values of Communication::Read() when running with and without read thread. Prior to this change, Read() would return eConnectionStatusSuccess if read thread was enabled and the read timed out or reached end-of-file, rather than the respective states that are returned if read thread was disabled. Now, it correctly returns eConnectionStatusTimedOut and eConnectionStatusEndOfFile, and sets the error respectively. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D132217 Added: Modified: lldb/source/Core/Communication.cpp lldb/unittests/Core/CommunicationTest.cpp Removed: diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp index d5f8f8922f5e1..56f0990d8c7f7 100644 --- a/lldb/source/Core/Communication.cpp +++ b/lldb/source/Core/Communication.cpp @@ -132,10 +132,16 @@ size_t Communication::Read(void *dst, size_t dst_len, if (m_read_thread_enabled) { // We have a dedicated read thread that is getting data for us size_t cached_bytes = GetCachedBytes(dst, dst_len); -if (cached_bytes > 0 || (timeout && timeout->count() == 0)) { +if (cached_bytes > 0) { status = eConnectionStatusSuccess; return cached_bytes; } +if (timeout && timeout->count() == 0) { + if (error_ptr) +error_ptr->SetErrorString("Timed out."); + status = eConnectionStatusTimedOut; + return 0; +} if (!m_connection_sp) { if (error_ptr) @@ -155,11 +161,25 @@ size_t Communication::Read(void *dst, size_t dst_len, } if (event_type & eBroadcastBitReadThreadDidExit) { +// If the thread exited of its own accord, it either means it +// hit an end-of-file condition or lost connection +// (we verified that we had an connection above). +if (!m_connection_sp) { + if (error_ptr) +error_ptr->SetErrorString("Lost connection."); + status = eConnectionStatusLostConnection; +} else + status = eConnectionStatusEndOfFile; + if (GetCloseOnEOF()) Disconnect(nullptr); -break; +return 0; } } + +if (error_ptr) + error_ptr->SetErrorString("Timed out."); +status = eConnectionStatusTimedOut; return 0; } diff --git a/lldb/unittests/Core/CommunicationTest.cpp b/lldb/unittests/Core/CommunicationTest.cpp index bb57a7b14670f..024684a486c2d 100644 --- a/lldb/unittests/Core/CommunicationTest.cpp +++ b/lldb/unittests/Core/CommunicationTest.cpp @@ -21,6 +21,72 @@ using namespace lldb_private; +static void CommunicationReadTest(bool use_read_thread) { + Pipe pipe; + ASSERT_THAT_ERROR(pipe.CreateNew(/*child_process_inherit=*/false).ToError(), +llvm::Succeeded()); + + Status error; + size_t bytes_written; + ASSERT_THAT_ERROR(pipe.Write("test", 4, bytes_written).ToError(), +llvm::Succeeded()); + ASSERT_EQ(bytes_written, 4U); + + Communication comm("test"); + comm.SetConnection(std::make_unique( + pipe.ReleaseReadFileDescriptor(), /*owns_fd=*/true)); + comm.SetCloseOnEOF(true); + + if (use_read_thread) +ASSERT_TRUE(comm.StartReadThread()); + + // This read should wait for the data to become available and return it. + lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess; + char buf[16]; + error.Clear(); + EXPECT_EQ( + comm.Read(buf, sizeof(buf), std::chrono::seconds(5), status, ), 4U); + EXPECT_EQ(status, lldb::eConnectionStatusSuccess); + EXPECT_THAT_ERROR(error.ToError(), llvm::Succeeded()); + buf[4] = 0; + EXPECT_STREQ(buf, "test"); + + // These reads should time out as there is no more data. + error.Clear(); + EXPECT_EQ(comm.Read(buf, sizeof(buf), std::chrono::microseconds(10), status, + ), +0U); + EXPECT_EQ(status, lldb::eConnectionStatusTimedOut); + EXPECT_THAT_ERROR(error.ToError(), llvm::Failed()); + + // 0 is special-cased, so we test it separately. + error.Clear(); + EXPECT_EQ( + comm.Read(buf, sizeof(buf), std::chrono::seconds(0), status, ), 0U); + EXPECT_EQ(status, lldb::eConnectionStatusTimedOut); + EXPECT_THAT_ERROR(error.ToError(), llvm::Failed()); + + // This read should return EOF. + pipe.CloseWriteFileDescriptor(); + error.Clear(); + EXPECT_EQ( + comm.Read(buf, sizeof(buf), std::chrono::seconds(5), status, ), 0U); + EXPECT_EQ(status, lldb::eConnectionStatusEndOfFile); + EXPECT_THAT_ERROR(error.ToError(),
[Lldb-commits] [lldb] 8b50ffe - [lldb] [test] Remove test_step_multiprocess, it's unreliable
Author: Michał Górny Date: 2022-08-19T10:08:11+02:00 New Revision: 8b50ffe9fdc3cd457796857d3661e34490ef0490 URL: https://github.com/llvm/llvm-project/commit/8b50ffe9fdc3cd457796857d3661e34490ef0490 DIFF: https://github.com/llvm/llvm-project/commit/8b50ffe9fdc3cd457796857d3661e34490ef0490.diff LOG: [lldb] [test] Remove test_step_multiprocess, it's unreliable Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/functionalities/gdb_remote_client/TestContinue.py Removed: diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py b/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py index 9c3fa66608d0..f0f0df81d321 100644 --- a/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py @@ -66,25 +66,3 @@ class MyResponder(self.BaseResponder): target = self.createTarget("a.yaml") process = self.connect(target) self.assertPacketLogContains(["vCont;C13:p400.401"]) - -# uses 'S13' instead of 's' arm (the pc dance?), testing it on one -# arch should be entirely sufficient -@skipIf(archs=no_match(["x86_64"])) -def test_step_multiprocess(self): -class MyResponder(self.BaseResponder): -def other(self, packet): -if packet == "vCont?": -return "vCont;c;C;s;S" -if packet.startswith("vCont;C"): -return "S13" -if packet.startswith("vCont;s"): -return "W00" -return "" - -self.server.responder = MyResponder() -self.runCmd("platform select remote-linux") -target = self.createTarget("a.yaml") -process = self.connect(target) -thread = process.GetSelectedThread() -thread.StepInstruction(False) -self.assertPacketLogContains(["vCont;s:p400.401"]) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 5815708 - [lldb] [test] Skip step packet test on non-amd64
Author: Michał Górny Date: 2022-08-19T09:48:13+02:00 New Revision: 58157087b0a4fefeabd4cf6e4ee356d6152fd5a6 URL: https://github.com/llvm/llvm-project/commit/58157087b0a4fefeabd4cf6e4ee356d6152fd5a6 DIFF: https://github.com/llvm/llvm-project/commit/58157087b0a4fefeabd4cf6e4ee356d6152fd5a6.diff LOG: [lldb] [test] Skip step packet test on non-amd64 Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/functionalities/gdb_remote_client/TestContinue.py Removed: diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py b/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py index 14147fb5b2bf..9c3fa66608d0 100644 --- a/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestContinue.py @@ -67,6 +67,9 @@ class MyResponder(self.BaseResponder): process = self.connect(target) self.assertPacketLogContains(["vCont;C13:p400.401"]) +# uses 'S13' instead of 's' arm (the pc dance?), testing it on one +# arch should be entirely sufficient +@skipIf(archs=no_match(["x86_64"])) def test_step_multiprocess(self): class MyResponder(self.BaseResponder): def other(self, packet): ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] ccb9d4d - [lldb] [gdb-remote] Include PID in vCont packets if multiprocess
Author: Michał Górny Date: 2022-08-19T09:02:20+02:00 New Revision: ccb9d4d4addc2fb2aa94cf776d43d8be35365272 URL: https://github.com/llvm/llvm-project/commit/ccb9d4d4addc2fb2aa94cf776d43d8be35365272 DIFF: https://github.com/llvm/llvm-project/commit/ccb9d4d4addc2fb2aa94cf776d43d8be35365272.diff LOG: [lldb] [gdb-remote] Include PID in vCont packets if multiprocess Try to always send vCont packets and include the PID in them if running multiprocess. This is necessary to ensure that with the upcoming full multiprocess support always resumes the correct process without having to resort to the legacy Hc packets. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D131758 Added: lldb/test/API/functionalities/gdb_remote_client/TestContinue.py Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 29417b35fde3a..11d0fec1926ab 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -181,6 +181,12 @@ bool GDBRemoteCommunicationClient::GetQXferSigInfoReadSupported() { return m_supports_qXfer_siginfo_read == eLazyBoolYes; } +bool GDBRemoteCommunicationClient::GetMultiprocessSupported() { + if (m_supports_memory_tagging == eLazyBoolCalculate) +GetRemoteQSupported(); + return m_supports_multiprocess == eLazyBoolYes; +} + uint64_t GDBRemoteCommunicationClient::GetRemoteMaxPacketSize() { if (m_max_packet_size == 0) { GetRemoteQSupported(); @@ -1514,7 +1520,7 @@ Status GDBRemoteCommunicationClient::Detach(bool keep_stopped, } } - if (m_supports_multiprocess) { + if (GetMultiprocessSupported()) { // Some servers (e.g. qemu) require specifying the PID even if only a single // process is running. if (pid == LLDB_INVALID_PROCESS_ID) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index 3a62747603f6d..4e89ade772ad3 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -339,6 +339,8 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase { bool GetQXferSigInfoReadSupported(); + bool GetMultiprocessSupported(); + LazyBool SupportsAllocDeallocMemory() // const { // Uncomment this to have lldb pretend the debug server doesn't respond to diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 30fb27932d192..0c876a8fd703e 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1186,11 +1186,15 @@ Status ProcessGDBRemote::DoResume() { StreamString continue_packet; bool continue_packet_error = false; if (m_gdb_comm.HasAnyVContSupport()) { + std::string pid_prefix; + if (m_gdb_comm.GetMultiprocessSupported()) +pid_prefix = llvm::formatv("p{0:x-}.", GetID()); + if (m_continue_c_tids.size() == num_threads || (m_continue_c_tids.empty() && m_continue_C_tids.empty() && m_continue_s_tids.empty() && m_continue_S_tids.empty())) { -// All threads are continuing, just send a "c" packet -continue_packet.PutCString("c"); +// All threads are continuing +continue_packet.Format("vCont;c:{0}-1", pid_prefix); } else { continue_packet.PutCString("vCont"); @@ -1200,7 +1204,7 @@ Status ProcessGDBRemote::DoResume() { t_pos = m_continue_c_tids.begin(), t_end = m_continue_c_tids.end(); t_pos != t_end; ++t_pos) - continue_packet.Printf(";c:%4.4" PRIx64, *t_pos); + continue_packet.Format(";c:{0}{1:x-}", pid_prefix, *t_pos); } else continue_packet_error = true; } @@ -1211,8 +1215,8 @@ Status ProcessGDBRemote::DoResume() { s_pos = m_continue_C_tids.begin(), s_end = m_continue_C_tids.end(); s_pos != s_end; ++s_pos) - continue_packet.Printf(";C%2.2x:%4.4" PRIx64, s_pos->second, - s_pos->first); + continue_packet.Format(";C{0:x-2}:{1}{2:x-}", s_pos->second, + pid_prefix, s_pos->first); } else
[Lldb-commits] [lldb] 9ba71d0 - [lldb] [gdb-remote] Remove unimplemented ProcessIDIsValid() (NFC)
Author: Michał Górny Date: 2022-08-12T11:17:15+02:00 New Revision: 9ba71d03b0f0ec82b7f74ec52818236237680348 URL: https://github.com/llvm/llvm-project/commit/9ba71d03b0f0ec82b7f74ec52818236237680348 DIFF: https://github.com/llvm/llvm-project/commit/9ba71d03b0f0ec82b7f74ec52818236237680348.diff LOG: [lldb] [gdb-remote] Remove unimplemented ProcessIDIsValid() (NFC) This method is not implemented and not referenced anywhere in the code. Sponsored by: The FreeBSD Foundation Added: Modified: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index 6ad9b3effe7b0..8e2a462f61212 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -308,8 +308,6 @@ class ProcessGDBRemote : public Process, bool HasExited(lldb::StateType state) { return state == lldb::eStateExited; } - bool ProcessIDIsValid() const; - void Clear(); bool DoUpdateThreadList(ThreadList _thread_list, ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 9b031d5 - [lldb] Make Process and subclass constructors protected
Author: Michał Górny Date: 2022-08-08T17:34:27+02:00 New Revision: 9b031d5e3a7b455308257a71116a603e76c8c679 URL: https://github.com/llvm/llvm-project/commit/9b031d5e3a7b455308257a71116a603e76c8c679 DIFF: https://github.com/llvm/llvm-project/commit/9b031d5e3a7b455308257a71116a603e76c8c679.diff LOG: [lldb] Make Process and subclass constructors protected Make constructors of the Process and its subclasses class protected, to prevent accidentally constructing Process on stack when it could be afterwards accessed via a shared_ptr (since it uses std::enable_shared_from_this<>). The only place where a stack allocation was used were unittests, and fixing them via declaring an explicit public constructor in the respective mock classes is trivial. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D131275 Added: Modified: lldb/include/lldb/Target/PostMortemProcess.h lldb/include/lldb/Target/Process.h lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp lldb/source/Plugins/Process/scripted/ScriptedProcess.h lldb/unittests/Expression/DWARFExpressionTest.cpp lldb/unittests/Process/ProcessEventDataTest.cpp lldb/unittests/Target/ExecutionContextTest.cpp lldb/unittests/Thread/ThreadTest.cpp Removed: diff --git a/lldb/include/lldb/Target/PostMortemProcess.h b/lldb/include/lldb/Target/PostMortemProcess.h index 353bfc0919eec..7207fc99ef29a 100644 --- a/lldb/include/lldb/Target/PostMortemProcess.h +++ b/lldb/include/lldb/Target/PostMortemProcess.h @@ -21,9 +21,9 @@ namespace lldb_private { /// between these kinds of processes can have default implementations in this /// class. class PostMortemProcess : public Process { -public: using Process::Process; +public: bool IsLiveDebugSession() const override { return false; } }; diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 505e211e09b63..05b0eb6237c71 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -475,15 +475,6 @@ class Process : public std::enable_shared_from_this, const ProcessEventData =(const ProcessEventData &) = delete; }; - /// Construct with a shared pointer to a target, and the Process listener. - /// Uses the Host UnixSignalsSP by default. - Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp); - - /// Construct with a shared pointer to a target, the Process listener, and - /// the appropriate UnixSignalsSP for the process. - Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, - const lldb::UnixSignalsSP _signals_sp); - /// Destructor. /// /// The destructor is virtual since this class is designed to be inherited @@ -2499,6 +2490,16 @@ void PruneThreadPlans(); protected: friend class Trace; + + /// Construct with a shared pointer to a target, and the Process listener. + /// Uses the Host UnixSignalsSP by default. + Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp); + + /// Construct with a shared pointer to a target, the Process listener, and + /// the appropriate UnixSignalsSP for the process. + Process(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, + const lldb::UnixSignalsSP _signals_sp); + /// Get the processor tracing type supported for this process. /// Responses might be diff erent depending on the architecture and /// capabilities of the underlying OS. diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h index 043fd0f0f5a54..bf9e5fe7a633c 100644 --- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h +++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h @@ -36,9 +36,6 @@ class ProcessWindows : public Process, public ProcessDebugger { static llvm::StringRef GetPluginDescriptionStatic(); - // Constructors and destructors - ProcessWindows(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp); - ~ProcessWindows(); size_t GetSTDOUT(char *buf, size_t buf_size, Status ) override; @@ -104,6 +101,8 @@ class ProcessWindows : public Process, public ProcessDebugger { Status DisableWatchpoint(Watchpoint *wp, bool notify = true) override; protected: + ProcessWindows(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp); + Status DoGetMemoryRegionInfo(lldb::addr_t vm_addr, MemoryRegionInfo ) override; diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 233a665f65904..30fb27932d192 100644 ---
[Lldb-commits] [lldb] 3426fc7 - Revert "[lldb] [gdb-remote] Send interrupt packets from async thread"
Author: Michał Górny Date: 2022-08-03T19:09:35+02:00 New Revision: 3426fc7318fe555ee37db14525e9bf024760fde2 URL: https://github.com/llvm/llvm-project/commit/3426fc7318fe555ee37db14525e9bf024760fde2 DIFF: https://github.com/llvm/llvm-project/commit/3426fc7318fe555ee37db14525e9bf024760fde2.diff LOG: Revert "[lldb] [gdb-remote] Send interrupt packets from async thread" This reverts commit 446b61cff4ea0cb7e7fcc5e0fec7bc749d379b08. Of course it does not work on Windows. Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp index f4bf2d164449b..e3a3cfc4f23ea 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp @@ -11,7 +11,6 @@ #include "llvm/ADT/StringExtras.h" #include "lldb/Target/UnixSignals.h" -#include "lldb/Utility/Connection.h" #include "lldb/Utility/LLDBAssert.h" #include "ProcessGDBRemoteLog.h" @@ -53,15 +52,13 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse( if (!cont_lock) return eStateInvalid; OnRunPacketSent(true); - // The main ReadPacket loop wakes up at computed_timeout intervals, just to + // The main ReadPacket loop wakes up at computed_timeout intervals, just to // check that the connection hasn't dropped. When we wake up we also check // whether there is an interrupt request that has reached its endpoint. - // If we want a shorter interrupt timeout that kWakeupInterval, we need to + // If we want a shorter interrupt timeout that kWakeupInterval, we need to // choose the shorter interval for the wake up as well. - std::chrono::seconds computed_timeout = - std::min(interrupt_timeout, kWakeupInterval); - std::chrono::time_point interrupt_endpoint; - bool interrupt_sent = false; + std::chrono::seconds computed_timeout = std::min(interrupt_timeout, + kWakeupInterval); for (;;) { PacketResult read_result = ReadPacket(response, computed_timeout, false); // Reset the computed_timeout to the default value in case we are going @@ -73,35 +70,16 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse( if (m_async_count == 0) { continue; } - if (!interrupt_sent) { -const char ctrl_c = '\x03'; -ConnectionStatus status = eConnectionStatusSuccess; -size_t bytes_written = Write(_c, 1, status, nullptr); -if (bytes_written == 0) { - LLDB_LOG(log, "failed to send interrupt packet"); - return eStateInvalid; -} -interrupt_endpoint = steady_clock::now() + interrupt_timeout; -if (log) - log->PutCString( - "GDBRemoteClientBase::SendContinuePacketAndWaitForResponse sent " - "packet: \\x03"); - -interrupt_sent = true; -continue; - } - auto cur_time = steady_clock::now(); - if (cur_time >= interrupt_endpoint) + if (cur_time >= m_interrupt_endpoint) return eStateInvalid; else { // We woke up and found an interrupt is in flight, but we haven't // exceeded the interrupt wait time. So reset the wait time to the // time left till the interrupt timeout. But don't wait longer // than our wakeup timeout. -auto new_wait = interrupt_endpoint - cur_time; -computed_timeout = std::min( -kWakeupInterval, +auto new_wait = m_interrupt_endpoint - cur_time; +computed_timeout = std::min(kWakeupInterval, std::chrono::duration_cast(new_wait)); continue; } @@ -369,6 +347,7 @@ GDBRemoteClientBase::Lock::Lock(GDBRemoteClientBase , } void GDBRemoteClientBase::Lock::SyncWithContinueThread() { + Log *log = GetLog(GDBRLog::Process|GDBRLog::Packets); std::unique_lock lock(m_comm.m_mutex); if (m_comm.m_is_running && m_interrupt_timeout == std::chrono::seconds(0)) return; // We were asked to avoid interrupting the sender. Lock is not @@ -376,11 +355,22 @@ void GDBRemoteClientBase::Lock::SyncWithContinueThread() { ++m_comm.m_async_count; if (m_comm.m_is_running) { -// SendContinuePacketAndWaitForResponse() takes care of sending -// the actual interrupt packet since we've increased m_async_count. -// Interrupt the ReadPacket() call to avoid having to wait for -// the interrupt timeout. -m_comm.GetConnection()->InterruptRead(); +if (m_comm.m_async_count == 1) { + // The sender has sent the continue packet and we are the first async + // packet. Let's interrupt it. + const char ctrl_c = '\x03'; +
[Lldb-commits] [lldb] 446b61c - [lldb] [gdb-remote] Send interrupt packets from async thread
Author: Michał Górny Date: 2022-08-03T18:40:25+02:00 New Revision: 446b61cff4ea0cb7e7fcc5e0fec7bc749d379b08 URL: https://github.com/llvm/llvm-project/commit/446b61cff4ea0cb7e7fcc5e0fec7bc749d379b08 DIFF: https://github.com/llvm/llvm-project/commit/446b61cff4ea0cb7e7fcc5e0fec7bc749d379b08.diff LOG: [lldb] [gdb-remote] Send interrupt packets from async thread Refactor the mechanism for sending interrupt packets to send them from async thread (i.e. the same thread that sends the continue packet preceding them and that waits for the response), rather than from the thread requesting the interrupt. This is going to become especially important when using the vCtrlC packet as part of the non-stop protocol, as -- unlike the simple ^c sent in the all-stop mode -- this packet involves an explicit reply. Suggested by Pavel Labath in D126614. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D131075 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp index e3a3cfc4f23ea..f4bf2d164449b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp @@ -11,6 +11,7 @@ #include "llvm/ADT/StringExtras.h" #include "lldb/Target/UnixSignals.h" +#include "lldb/Utility/Connection.h" #include "lldb/Utility/LLDBAssert.h" #include "ProcessGDBRemoteLog.h" @@ -52,13 +53,15 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse( if (!cont_lock) return eStateInvalid; OnRunPacketSent(true); - // The main ReadPacket loop wakes up at computed_timeout intervals, just to + // The main ReadPacket loop wakes up at computed_timeout intervals, just to // check that the connection hasn't dropped. When we wake up we also check // whether there is an interrupt request that has reached its endpoint. - // If we want a shorter interrupt timeout that kWakeupInterval, we need to + // If we want a shorter interrupt timeout that kWakeupInterval, we need to // choose the shorter interval for the wake up as well. - std::chrono::seconds computed_timeout = std::min(interrupt_timeout, - kWakeupInterval); + std::chrono::seconds computed_timeout = + std::min(interrupt_timeout, kWakeupInterval); + std::chrono::time_point interrupt_endpoint; + bool interrupt_sent = false; for (;;) { PacketResult read_result = ReadPacket(response, computed_timeout, false); // Reset the computed_timeout to the default value in case we are going @@ -70,16 +73,35 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse( if (m_async_count == 0) { continue; } + if (!interrupt_sent) { +const char ctrl_c = '\x03'; +ConnectionStatus status = eConnectionStatusSuccess; +size_t bytes_written = Write(_c, 1, status, nullptr); +if (bytes_written == 0) { + LLDB_LOG(log, "failed to send interrupt packet"); + return eStateInvalid; +} +interrupt_endpoint = steady_clock::now() + interrupt_timeout; +if (log) + log->PutCString( + "GDBRemoteClientBase::SendContinuePacketAndWaitForResponse sent " + "packet: \\x03"); + +interrupt_sent = true; +continue; + } + auto cur_time = steady_clock::now(); - if (cur_time >= m_interrupt_endpoint) + if (cur_time >= interrupt_endpoint) return eStateInvalid; else { // We woke up and found an interrupt is in flight, but we haven't // exceeded the interrupt wait time. So reset the wait time to the // time left till the interrupt timeout. But don't wait longer // than our wakeup timeout. -auto new_wait = m_interrupt_endpoint - cur_time; -computed_timeout = std::min(kWakeupInterval, +auto new_wait = interrupt_endpoint - cur_time; +computed_timeout = std::min( +kWakeupInterval, std::chrono::duration_cast(new_wait)); continue; } @@ -347,7 +369,6 @@ GDBRemoteClientBase::Lock::Lock(GDBRemoteClientBase , } void GDBRemoteClientBase::Lock::SyncWithContinueThread() { - Log *log = GetLog(GDBRLog::Process|GDBRLog::Packets); std::unique_lock lock(m_comm.m_mutex); if (m_comm.m_is_running && m_interrupt_timeout == std::chrono::seconds(0)) return; // We were asked to avoid interrupting the sender. Lock is not @@ -355,22 +376,11 @@ void GDBRemoteClientBase::Lock::SyncWithContinueThread() { ++m_comm.m_async_count; if (m_comm.m_is_running) { -if
[Lldb-commits] [lldb] f8603c1 - [lldb] [llgs] Support resuming multiple processes via vCont w/ nonstop
Author: Michał Górny Date: 2022-08-01T18:52:47+02:00 New Revision: f8603c1f6d9eb90bc6a674111bd3441458006601 URL: https://github.com/llvm/llvm-project/commit/f8603c1f6d9eb90bc6a674111bd3441458006601 DIFF: https://github.com/llvm/llvm-project/commit/f8603c1f6d9eb90bc6a674111bd3441458006601.diff LOG: [lldb] [llgs] Support resuming multiple processes via vCont w/ nonstop Support using the vCont packet to resume multiple processes simultaneously when in non-stop mode. The new logic now assumes that: - actions without a thread-id or with process id of "p-1" apply to all debugged processes - actions with a thread-id without process id apply to the current process (m_continue_process) As with the other continue packets, it is only possible to resume processes that are currently stopped (or stop these that are running). It is unsupported to resume or stop individual threads of a running process. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128989 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 20650b5c8820d..d1b30f74f0bfb 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1762,6 +1762,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont( break; } +// If there's no thread-id (e.g. "vCont;c"), it's "p-1.-1". lldb::pid_t pid = StringExtractorGDBRemote::AllProcesses; lldb::tid_t tid = StringExtractorGDBRemote::AllThreads; @@ -1770,7 +1771,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont( // Consume the separator. packet.GetChar(); - auto pid_tid = packet.GetPidTid(StringExtractorGDBRemote::AllProcesses); + auto pid_tid = packet.GetPidTid(LLDB_INVALID_PROCESS_ID); if (!pid_tid) return SendIllFormedResponse(packet, "Malformed thread-id"); @@ -1784,29 +1785,35 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont( packet, "'t' action not supported for individual threads"); } -if (pid == StringExtractorGDBRemote::AllProcesses) { - if (m_debugged_processes.size() > 1) -return SendIllFormedResponse( -packet, "Resuming multiple processes not supported yet"); +// If we get TID without PID, it's the current process. +if (pid == LLDB_INVALID_PROCESS_ID) { if (!m_continue_process) { -LLDB_LOG(log, "no debugged process"); +LLDB_LOG(log, "no process selected via Hc"); return SendErrorResponse(0x36); } pid = m_continue_process->GetID(); } +assert(pid != LLDB_INVALID_PROCESS_ID); if (tid == StringExtractorGDBRemote::AllThreads) tid = LLDB_INVALID_THREAD_ID; - thread_action.tid = tid; -thread_actions[pid].Append(thread_action); +if (pid == StringExtractorGDBRemote::AllProcesses) { + if (tid != LLDB_INVALID_THREAD_ID) +return SendIllFormedResponse( +packet, "vCont: p-1 is not valid with a specific tid"); + for (auto _it : m_debugged_processes) +thread_actions[process_it.first].Append(thread_action); +} else + thread_actions[pid].Append(thread_action); } assert(thread_actions.size() >= 1); - if (thread_actions.size() > 1) + if (thread_actions.size() > 1 && !m_non_stop) return SendIllFormedResponse( -packet, "Resuming multiple processes not supported yet"); +packet, +"Resuming multiple processes is supported in non-stop mode only"); for (std::pair x : thread_actions) { auto process_it = m_debugged_processes.find(x.first); diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py index daaa15e86ab4a..3714789d22337 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py @@ -150,3 +150,55 @@ def test_c_both_nonstop(self): self.assertEqual(output.count(b"PID: "), 2) self.assertIn("PID: {}".format(int(parent_pid, 16)).encode(), output) self.assertIn("PID: {}".format(int(child_pid, 16)).encode(), output) + +@add_test_categories(["fork"]) +def test_vCont_both_nonstop(self): +lock1 = self.getBuildArtifact("lock1") +lock2 = self.getBuildArtifact("lock2") +parent_pid, parent_tid, child_pid, child_tid = ( +self.start_fork_test(["fork", "process:sync:" + lock1, "print-pid", + "process:sync:" + lock2, "stop"], +
[Lldb-commits] [lldb] 0806927 - [lldb] [test] Fix test_c_both_nonstop flakiness
Author: Michał Górny Date: 2022-08-01T18:52:47+02:00 New Revision: 080692797724eefd15de00500d8d802e98230622 URL: https://github.com/llvm/llvm-project/commit/080692797724eefd15de00500d8d802e98230622 DIFF: https://github.com/llvm/llvm-project/commit/080692797724eefd15de00500d8d802e98230622.diff LOG: [lldb] [test] Fix test_c_both_nonstop flakiness Thanks to Pavel Labath for reporting this and suggesting a fix. Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py index 0868c32bdd322..daaa15e86ab4a 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py @@ -113,6 +113,16 @@ def test_vCont_interspersed_nonstop(self): self.resume_one_test(run_order=["parent", "child", "parent", "child"], use_vCont=True, nonstop=True) +def get_all_output_via_vStdio(self, output_test): +# The output may be split into an arbitrary number of messages. +# Loop until we have everything. The first message is waiting for us +# in the packet queue. +output = self._server.get_raw_output_packet() +while not output_test(output): +self._server.send_packet(b"vStdio") +output += self._server.get_raw_output_packet() +return output + @add_test_categories(["fork"]) def test_c_both_nonstop(self): lock1 = self.getBuildArtifact("lock1") @@ -132,13 +142,11 @@ def test_c_both_nonstop(self): "read packet: $c#00", "send packet: $OK#00", {"direction": "send", "regex": "%Stop:T.*"}, -# see the comment in TestNonStop.py, test_stdio -"read packet: $vStdio#00", -"read packet: $vStdio#00", -"send packet: $OK#00", ], True) -ret = self.expect_gdbremote_sequence() -self.assertIn("PID: {}".format(int(parent_pid, 16)).encode(), - ret["O_content"]) -self.assertIn("PID: {}".format(int(child_pid, 16)).encode(), - ret["O_content"]) +self.expect_gdbremote_sequence() + +output = self.get_all_output_via_vStdio( +lambda output: output.count(b"PID: ") >= 2) +self.assertEqual(output.count(b"PID: "), 2) +self.assertIn("PID: {}".format(int(parent_pid, 16)).encode(), output) +self.assertIn("PID: {}".format(int(child_pid, 16)).encode(), output) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 8068751 - [lldb] [gdb-remote] Refactor killing process and move it to client
Author: Michał Górny Date: 2022-07-25T18:43:32+02:00 New Revision: 8068751189af3099d9abef8953a9639d6798535c URL: https://github.com/llvm/llvm-project/commit/8068751189af3099d9abef8953a9639d6798535c DIFF: https://github.com/llvm/llvm-project/commit/8068751189af3099d9abef8953a9639d6798535c.diff LOG: [lldb] [gdb-remote] Refactor killing process and move it to client Refactor the code responsible for sending the "k" packet and move it into GDBRemoteCommunicationClient::KillProcess() method. This is part of refactoring to enable multiprocess support in the client, and to support using the vKill packet instead. As part of the refactoring, the following functional changes apply: - Some redundant logging has been removed, as any failures are returned via exit_string anyway. - SetLastStopPacket() is no longer called. It is used only to populate the thread list, and since the process has just exited and we're terminating the process instance, there's really no reason to set it. - On successful kill, exit_string is set to "killed", to clearly indicate that the process has terminated on our request rather than on its own. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D130340 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index c44ace96dd55c..580cdde57d80f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -4265,3 +4265,21 @@ bool GDBRemoteCommunicationClient::UsesNativeSignals() { // check whether it is an old version of lldb-server. return GetThreadSuffixSupported(); } + +llvm::Expected GDBRemoteCommunicationClient::KillProcess(lldb::pid_t pid) { + StringExtractorGDBRemote response; + GDBRemoteCommunication::ScopedTimeout(*this, seconds(3)); + + if (SendPacketAndWaitForResponse("k", response, GetPacketTimeout()) != + PacketResult::Success) +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "failed to send k packet"); + + char packet_cmd = response.GetChar(0); + if (packet_cmd == 'W' || packet_cmd == 'X') +return response.GetHexU8(); + + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "unexpected response to k packet: %s", + response.GetStringRef().str().c_str()); +} diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index d367f75cee0e9..3d838d6d80747 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -521,6 +521,8 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase { bool GetSaveCoreSupported() const; + llvm::Expected KillProcess(lldb::pid_t pid); + protected: LazyBool m_supports_not_sending_acks = eLazyBoolCalculate; LazyBool m_supports_thread_suffix = eLazyBoolCalculate; diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 5f18706f67e5d..3e1a6fb6620a7 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -2394,7 +2394,6 @@ Status ProcessGDBRemote::DoDetach(bool keep_stopped) { } Status ProcessGDBRemote::DoDestroy() { - Status error; Log *log = GetLog(GDBRLog::Process); LLDB_LOGF(log, "ProcessGDBRemote::DoDestroy()"); @@ -2404,54 +2403,35 @@ Status ProcessGDBRemote::DoDestroy() { if (m_gdb_comm.IsConnected()) { if (m_public_state.GetValue() != eStateAttaching) { - StringExtractorGDBRemote response; - GDBRemoteCommunication::ScopedTimeout(m_gdb_comm, -std::chrono::seconds(3)); - - if (m_gdb_comm.SendPacketAndWaitForResponse("k", response, - GetInterruptTimeout()) == - GDBRemoteCommunication::PacketResult::Success) { -char packet_cmd = response.GetChar(0); + llvm::Expected kill_res = m_gdb_comm.KillProcess(GetID()); -if (packet_cmd == 'W' || packet_cmd == 'X') { + if (kill_res) { +exit_status = kill_res.get(); #if defined(__APPLE__) - // For Native processes on Mac OS X, we launch through the Host - // Platform, then hand the
[Lldb-commits] [lldb] b61b8ef - [lldb] [gdb-remote] Fix process ID after following forked child
Author: Michał Górny Date: 2022-07-21T17:11:38+02:00 New Revision: b61b8efcf31b3d53377b9cf6cb3eb87742602ff6 URL: https://github.com/llvm/llvm-project/commit/b61b8efcf31b3d53377b9cf6cb3eb87742602ff6 DIFF: https://github.com/llvm/llvm-project/commit/b61b8efcf31b3d53377b9cf6cb3eb87742602ff6.diff LOG: [lldb] [gdb-remote] Fix process ID after following forked child Update the process ID after handling fork/vfork to ensure that the process plugin reports the correct PID immediately. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D130037 Added: Modified: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/test/API/functionalities/gdb_remote_client/TestFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index fe6a3f9ed6c19..5f18706f67e5d 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -5307,8 +5307,11 @@ void ProcessGDBRemote::DidFork(lldb::pid_t child_pid, lldb::tid_t child_tid) { // Hardware breakpoints/watchpoints are not inherited implicitly, // so we need to readd them if we're following child. - if (GetFollowForkMode() == eFollowChild) + if (GetFollowForkMode() == eFollowChild) { DidForkSwitchHardwareTraps(true); +// Update our PID +SetID(child_pid); + } } void ProcessGDBRemote::DidVFork(lldb::pid_t child_pid, lldb::tid_t child_tid) { @@ -5361,6 +5364,11 @@ void ProcessGDBRemote::DidVFork(lldb::pid_t child_pid, lldb::tid_t child_tid) { error.AsCString() ? error.AsCString() : ""); return; } + + if (GetFollowForkMode() == eFollowChild) { +// Update our PID +SetID(child_pid); + } } void ProcessGDBRemote::DidVForkDone() { diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestFork.py b/lldb/test/API/functionalities/gdb_remote_client/TestFork.py index 79fa520fe22dd..bf66f25a55186 100644 --- a/lldb/test/API/functionalities/gdb_remote_client/TestFork.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestFork.py @@ -9,7 +9,7 @@ class TestMultiprocess(GDBRemoteTestBase): -def base_test(self, variant): +def base_test(self, variant, follow_child=False): class MyResponder(MockGDBServerResponder): def __init__(self): super().__init__() @@ -43,12 +43,24 @@ def D(self, packet): self.runCmd("log enable gdb-remote packets") self.addTearDownHook( lambda: self.runCmd("log disable gdb-remote packets")) +if follow_child: +self.runCmd("settings set target.process.follow-fork-mode child") process = self.connect(target) +self.assertEqual(process.GetProcessID(), 1024) process.Continue() -self.assertRegex(self.server.responder.detached, r"D;0*401") +self.assertRegex(self.server.responder.detached, + r"D;0*400" if follow_child else r"D;0*401") +self.assertEqual(process.GetProcessID(), + 1025 if follow_child else 1024) def test_fork(self): self.base_test("fork") def test_vfork(self): self.base_test("vfork") + +def test_fork_follow_child(self): +self.base_test("fork", follow_child=True) + +def test_vfork_follow_child(self): +self.base_test("vfork", follow_child=True) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 09531ed - [lldb] [llgs] Improve stdio forwarding in multiprocess+nonstop
Author: Michał Górny Date: 2022-07-15T21:50:39+02:00 New Revision: 09531ede6d5622da68941902072dbca517d31318 URL: https://github.com/llvm/llvm-project/commit/09531ede6d5622da68941902072dbca517d31318 DIFF: https://github.com/llvm/llvm-project/commit/09531ede6d5622da68941902072dbca517d31318.diff LOG: [lldb] [llgs] Improve stdio forwarding in multiprocess+nonstop Enable stdio forwarding when nonstop mode is enabled, and disable it once it is disabled. This makes it possible to cleanly handle stdio forwarding while running multiple processes in non-stop mode. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128932 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py lldb/test/API/tools/lldb-server/main.cpp Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index be789bdf7da5..5804c13fe7b6 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1113,14 +1113,16 @@ void GDBRemoteCommunicationServerLLGS::ProcessStateChanged( SendProcessOutput(); // Then stop the forwarding, so that any late output (see llvm.org/pr25652) // does not interfere with our protocol. -StopSTDIOForwarding(); +if (!m_non_stop) + StopSTDIOForwarding(); HandleInferiorState_Stopped(process); break; case StateType::eStateExited: // Same as above SendProcessOutput(); -StopSTDIOForwarding(); +if (!m_non_stop) + StopSTDIOForwarding(); HandleInferiorState_Exited(process); break; @@ -1425,7 +1427,8 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_k(StringExtractorGDBRemote ) { Log *log = GetLog(LLDBLog::Process); - StopSTDIOForwarding(); + if (!m_non_stop) +StopSTDIOForwarding(); if (m_debugged_processes.empty()) { LLDB_LOG(log, "No debugged process found."); @@ -1451,7 +1454,8 @@ GDBRemoteCommunicationServerLLGS::Handle_k(StringExtractorGDBRemote ) { GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_vKill( StringExtractorGDBRemote ) { - StopSTDIOForwarding(); + if (!m_non_stop) +StopSTDIOForwarding(); packet.SetFilePos(6); // vKill; uint32_t pid = packet.GetU32(LLDB_INVALID_PROCESS_ID, 16); @@ -3524,7 +3528,8 @@ GDBRemoteCommunicationServerLLGS::Handle_vRun( GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote ) { Log *log = GetLog(LLDBLog::Process); - StopSTDIOForwarding(); + if (!m_non_stop) +StopSTDIOForwarding(); lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; @@ -3923,6 +3928,8 @@ GDBRemoteCommunicationServerLLGS::Handle_QNonStop( assert(packet_str.startswith("QNonStop:")); packet_str.consume_front("QNonStop:"); if (packet_str == "0") { +if (m_non_stop) + StopSTDIOForwarding(); for (auto _it : m_debugged_processes) { if (process_it.second.process_up->IsRunning()) { assert(m_non_stop); @@ -3945,6 +3952,8 @@ GDBRemoteCommunicationServerLLGS::Handle_QNonStop( if (m_disabling_non_stop) return PacketResult::Success; } else if (packet_str == "1") { +if (!m_non_stop) + StartSTDIOForwarding(); m_non_stop = true; } else return SendErrorResponse(Status("Invalid QNonStop packet")); @@ -4238,9 +4247,10 @@ void GDBRemoteCommunicationServerLLGS::SetEnabledExtensions( GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::SendContinueSuccessResponse() { - // TODO: how to handle forwarding in non-stop mode? + if (m_non_stop) +return SendOKResponse(); StartSTDIOForwarding(); - return m_non_stop ? SendOKResponse() : PacketResult::Success; + return PacketResult::Success; } void GDBRemoteCommunicationServerLLGS::AppendThreadIDToResponse( diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py index 7ba376485513..0868c32bdd32 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py @@ -112,3 +112,33 @@ def test_c_interspersed_nonstop(self): def test_vCont_interspersed_nonstop(self): self.resume_one_test(run_order=["parent", "child", "parent", "child"], use_vCont=True, nonstop=True) + +@add_test_categories(["fork"]) +def test_c_both_nonstop(self): +lock1 = self.getBuildArtifact("lock1") +lock2 = self.getBuildArtifact("lock2") +parent_pid, parent_tid, child_pid, child_tid = ( +
[Lldb-commits] [lldb] fc92f11 - [lldb] [test] Skip test_leave_nonstop on Windows
Author: Michał Górny Date: 2022-07-15T21:48:03+02:00 New Revision: fc92f11441894e65f76a856cfc55a03e0df726a6 URL: https://github.com/llvm/llvm-project/commit/fc92f11441894e65f76a856cfc55a03e0df726a6 DIFF: https://github.com/llvm/llvm-project/commit/fc92f11441894e65f76a856cfc55a03e0df726a6.diff LOG: [lldb] [test] Skip test_leave_nonstop on Windows Added: Modified: lldb/test/API/tools/lldb-server/TestNonStop.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestNonStop.py b/lldb/test/API/tools/lldb-server/TestNonStop.py index 13cfe7ad3c6b..0031f1885e88 100644 --- a/lldb/test/API/tools/lldb-server/TestNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestNonStop.py @@ -363,6 +363,7 @@ def test_stop_reason_while_running(self): ], True) self.expect_gdbremote_sequence() +@skipIfWindows @add_test_categories(["llgs"]) def test_leave_nonstop(self): self.build() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] c732afa - [lldb] [llgs] Fix disabling non-stop mode
Author: Michał Górny Date: 2022-07-15T20:16:49+02:00 New Revision: c732afa2c2e8bf4c3d068af180c1e9daa25b03c1 URL: https://github.com/llvm/llvm-project/commit/c732afa2c2e8bf4c3d068af180c1e9daa25b03c1 DIFF: https://github.com/llvm/llvm-project/commit/c732afa2c2e8bf4c3d068af180c1e9daa25b03c1.diff LOG: [lldb] [llgs] Fix disabling non-stop mode Stop all processes and clear notification queues when disabling non-stop mode. Ensure that no stop notifications are sent for processes stopped due to the mode switch. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128893 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/test/API/tools/lldb-server/TestNonStop.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 1bc94658f1958..be789bdf7da50 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1919,6 +1919,20 @@ GDBRemoteCommunicationServerLLGS::SendStopReasonForState( bool force_synchronous) { Log *log = GetLog(LLDBLog::Process); + if (m_disabling_non_stop) { +// Check if we are waiting for any more processes to stop. If we are, +// do not send the OK response yet. +for (const auto : m_debugged_processes) { + if (it.second.process_up->IsRunning()) +return PacketResult::Success; +} + +// If all expected processes were stopped after a QNonStop:0 request, +// send the OK response. +m_disabling_non_stop = false; +return SendOKResponse(); + } + switch (process_state) { case eStateAttaching: case eStateLaunching: @@ -3903,12 +3917,33 @@ GDBRemoteCommunicationServerLLGS::Handle_qSaveCore( GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_QNonStop( StringExtractorGDBRemote ) { + Log *log = GetLog(LLDBLog::Process); + StringRef packet_str{packet.GetStringRef()}; assert(packet_str.startswith("QNonStop:")); packet_str.consume_front("QNonStop:"); if (packet_str == "0") { +for (auto _it : m_debugged_processes) { + if (process_it.second.process_up->IsRunning()) { +assert(m_non_stop); +Status error = process_it.second.process_up->Interrupt(); +if (error.Fail()) { + LLDB_LOG(log, + "while disabling nonstop, failed to halt process {0}: {1}", + process_it.first, error); + return SendErrorResponse(0x41); +} +// we must not send stop reasons after QNonStop +m_disabling_non_stop = true; + } +} +m_stdio_notification_queue.clear(); +m_stop_notification_queue.clear(); m_non_stop = false; -// TODO: stop all threads +// If we are stopping anything, defer sending the OK response until we're +// done. +if (m_disabling_non_stop) + return PacketResult::Success; } else if (packet_str == "1") { m_non_stop = true; } else diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h index 3d67032fc62d6..1165b60ac762b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -117,6 +117,7 @@ class GDBRemoteCommunicationServerLLGS bool m_thread_suffix_supported = false; bool m_list_threads_in_stop_reply = false; bool m_non_stop = false; + bool m_disabling_non_stop = false; std::deque m_stdio_notification_queue; std::deque m_stop_notification_queue; diff --git a/lldb/test/API/tools/lldb-server/TestNonStop.py b/lldb/test/API/tools/lldb-server/TestNonStop.py index 5f08aae0f2dbb..13cfe7ad3c6be 100644 --- a/lldb/test/API/tools/lldb-server/TestNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestNonStop.py @@ -362,3 +362,33 @@ def test_stop_reason_while_running(self): "send packet: $OK#00", ], True) self.expect_gdbremote_sequence() + +@add_test_categories(["llgs"]) +def test_leave_nonstop(self): +self.build() +self.set_inferior_startup_launch() +procs = self.prep_debug_monitor_and_inferior( +inferior_args=["thread:new", "thread:new", "stop", "sleep:15"]) +self.test_sequence.add_log_lines( +["read packet: $QNonStop:1#00", + "send packet: $OK#00", + # stop is used to synchronize starting threads + "read packet: $c#63", + "send packet: $OK#00", + {"direction":
[Lldb-commits] [lldb] 5d66597 - [lldb] [test] Skip test_stop_reason_while_running on Windows
Author: Michał Górny Date: 2022-07-15T20:14:55+02:00 New Revision: 5d6659739c4ed5f445dbdc5da499d84b5a8cebaa URL: https://github.com/llvm/llvm-project/commit/5d6659739c4ed5f445dbdc5da499d84b5a8cebaa DIFF: https://github.com/llvm/llvm-project/commit/5d6659739c4ed5f445dbdc5da499d84b5a8cebaa.diff LOG: [lldb] [test] Skip test_stop_reason_while_running on Windows Added: Modified: lldb/test/API/tools/lldb-server/TestNonStop.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestNonStop.py b/lldb/test/API/tools/lldb-server/TestNonStop.py index 29efd1cd725e3..5f08aae0f2dbb 100644 --- a/lldb/test/API/tools/lldb-server/TestNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestNonStop.py @@ -342,6 +342,7 @@ def test_stdio(self): ], True) self.expect_gdbremote_sequence() +@skipIfWindows @add_test_categories(["llgs"]) def test_stop_reason_while_running(self): self.build() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] ab9f1e8 - [lldb] [llgs] Fix `?` packet response for running threads
Author: Michał Górny Date: 2022-07-15T18:33:58+02:00 New Revision: ab9f1e88fd8a73a32914c18a52868d3a4b9e509e URL: https://github.com/llvm/llvm-project/commit/ab9f1e88fd8a73a32914c18a52868d3a4b9e509e DIFF: https://github.com/llvm/llvm-project/commit/ab9f1e88fd8a73a32914c18a52868d3a4b9e509e.diff LOG: [lldb] [llgs] Fix `?` packet response for running threads Fix the response to `?` packet for threads that are running at the time (in non-stop mode). The previous code would wrongly send or queue an empty response for them. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128879 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestNonStop.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 49f37ba7219f..1bc94658f195 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1025,9 +1025,11 @@ void GDBRemoteCommunicationServerLLGS::EnqueueStopReplyPackets( return; for (NativeThreadProtocol _thread : m_current_process->Threads()) { -if (listed_thread.GetID() != thread_to_skip) - m_stop_notification_queue.push_back( - PrepareStopReplyPacketForThread(listed_thread).GetString().str()); +if (listed_thread.GetID() != thread_to_skip) { + StreamString stop_reply = PrepareStopReplyPacketForThread(listed_thread); + if (!stop_reply.Empty()) +m_stop_notification_queue.push_back(stop_reply.GetString().str()); +} } } @@ -1885,9 +1887,11 @@ GDBRemoteCommunicationServerLLGS::Handle_stop_reason( // the current thread (for clients that don't actually support multiple // stop reasons). NativeThreadProtocol *thread = m_current_process->GetCurrentThread(); - if (thread) -m_stop_notification_queue.push_back( -PrepareStopReplyPacketForThread(*thread).GetString().str()); + if (thread) { +StreamString stop_reply = PrepareStopReplyPacketForThread(*thread); +if (!stop_reply.Empty()) + m_stop_notification_queue.push_back(stop_reply.GetString().str()); + } EnqueueStopReplyPackets(thread ? thread->GetID() : LLDB_INVALID_THREAD_ID); } diff --git a/lldb/test/API/tools/lldb-server/TestNonStop.py b/lldb/test/API/tools/lldb-server/TestNonStop.py index 8a9ed91f45be..29efd1cd725e 100644 --- a/lldb/test/API/tools/lldb-server/TestNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestNonStop.py @@ -341,3 +341,23 @@ def test_stdio(self): "send packet: $OK#00", ], True) self.expect_gdbremote_sequence() + +@add_test_categories(["llgs"]) +def test_stop_reason_while_running(self): +self.build() +self.set_inferior_startup_launch() +procs = self.prep_debug_monitor_and_inferior( +inferior_args=["thread:new", "thread:new", "stop", "sleep:15"]) +self.test_sequence.add_log_lines( +["read packet: $QNonStop:1#00", + "send packet: $OK#00", + # stop is used to synchronize starting threads + "read packet: $c#63", + "send packet: $OK#00", + {"direction": "send", "regex": "%Stop:T.*"}, + "read packet: $c#63", + "send packet: $OK#00", + "read packet: $?#00", + "send packet: $OK#00", + ], True) +self.expect_gdbremote_sequence() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[lldb] 81e993f - [lldb] [test] Skip TestNonStop → test_stdio on Windows
Author: Michał Górny Date: 2022-07-15T18:33:19+02:00 New Revision: 81e993f08d6cd8d1658e3843594449b6fa622a4f URL: https://github.com/llvm/llvm-project/commit/81e993f08d6cd8d1658e3843594449b6fa622a4f DIFF: https://github.com/llvm/llvm-project/commit/81e993f08d6cd8d1658e3843594449b6fa622a4f.diff LOG: [lldb] [test] Skip TestNonStop → test_stdio on Windows Added: Modified: lldb/test/API/tools/lldb-server/TestNonStop.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestNonStop.py b/lldb/test/API/tools/lldb-server/TestNonStop.py index e55ae0fa7c7d..8a9ed91f45be 100644 --- a/lldb/test/API/tools/lldb-server/TestNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestNonStop.py @@ -297,6 +297,7 @@ def test_vCont_then_partial_stop(self): def test_vCont_then_partial_stop_run_both(self): self.vCont_then_partial_stop_test(True) +@skipIfWindows @add_test_categories(["llgs"]) def test_stdio(self): self.build() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 1903f35 - [lldb] [llgs] Send process output asynchronously in non-stop mode
Author: Michał Górny Date: 2022-07-15T17:20:39+02:00 New Revision: 1903f358bcc74fd96c65f0d1deba577c63238c86 URL: https://github.com/llvm/llvm-project/commit/1903f358bcc74fd96c65f0d1deba577c63238c86 DIFF: https://github.com/llvm/llvm-project/commit/1903f358bcc74fd96c65f0d1deba577c63238c86.diff LOG: [lldb] [llgs] Send process output asynchronously in non-stop mode Introduce a new %Stdio notification category and use it to send process output asynchronously when running in non-stop mode. This is an LLDB extension since GDB does not use the 'O' packet for process output, just for replies to 'qRcmd' packets. Using the async notification mechanism implies that only the first output packet is sent immediately to the client. The client needs to request subsequent notifications (if any) using the new vStdio packet (that works pretty much like vStopped for the Stop notification queue). The packet handler in lldb-server tests is updated to handle the async stdio packets in addition to the regular O packets. However, due to the implications noted above, it can only handle the first output packet sent by the server. Subsequent packets need to be explicitly requested via vStdio. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128849 Added: Modified: lldb/include/lldb/Utility/StringExtractorGDBRemote.h lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/source/Utility/StringExtractorGDBRemote.cpp lldb/test/API/tools/lldb-server/TestNonStop.py Removed: diff --git a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h index c32ce0389116e..d869950ab6dd1 100644 --- a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h +++ b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h @@ -179,6 +179,7 @@ class StringExtractorGDBRemote : public StringExtractor { eServerPacketType_QNonStop, eServerPacketType_vStopped, eServerPacketType_vCtrlC, +eServerPacketType_vStdio, }; ServerPacketType GetServerPacketType() const; diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py index eff6dd6d53007..82e1685666bc0 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py @@ -79,26 +79,6 @@ def _is_packet_lldb_gdbserver_input(packet_type, llgs_input_is_read): raise "Unknown packet type: {}".format(packet_type) -def handle_O_packet(context, packet_contents, logger): -"""Handle O packets.""" -if (not packet_contents) or (len(packet_contents) < 1): -return False -elif packet_contents[0] != "O": -return False -elif packet_contents == "OK": -return False - -new_text = gdbremote_hex_decode_string(packet_contents[1:]) -context["O_content"] += new_text -context["O_count"] += 1 - -if logger: -logger.debug( -"text: new \"{}\", cumulative: \"{}\"".format( -new_text, context["O_content"])) - -return True - _STRIP_CHECKSUM_REGEX = re.compile(r'#[0-9a-fA-F]{2}$') _STRIP_COMMAND_PREFIX_REGEX = re.compile(r"^\$") _STRIP_COMMAND_PREFIX_M_REGEX = re.compile(r"^\$m") @@ -859,19 +839,21 @@ def process_is_running(pid, unknown_value=True): # Check if the pid is in the process_ids return pid in process_ids + def _handle_output_packet_string(packet_contents): -if (not packet_contents) or (len(packet_contents) < 1): +# Warning: in non-stop mode, we currently handle only the first output +# packet since we'd need to inject vStdio packets +if not packet_contents.startswith((b"$O", b"%Stdio:O")): return None -elif packet_contents[0:1] != b"O": -return None -elif packet_contents == b"OK": +elif packet_contents == b"$OK": return None else: -return binascii.unhexlify(packet_contents[1:]) +return binascii.unhexlify(packet_contents.partition(b"O")[2]) + class Server(object): -_GDB_REMOTE_PACKET_REGEX = re.compile(br'^[\$%]([^\#]*)#[0-9a-fA-F]{2}') +_GDB_REMOTE_PACKET_REGEX = re.compile(br'^([\$%][^\#]*)#[0-9a-fA-F]{2}') class ChecksumMismatch(Exception): pass diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 8edb49f06a334..49f37ba7219f0 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++
[Lldb-commits] [lldb] 5a6f1f3 - [lldb] [test] Skip new NonStop tests on Windows
Author: Michał Górny Date: 2022-07-15T16:02:47+02:00 New Revision: 5a6f1f3271720fffd9f82827f593737e1af7f833 URL: https://github.com/llvm/llvm-project/commit/5a6f1f3271720fffd9f82827f593737e1af7f833 DIFF: https://github.com/llvm/llvm-project/commit/5a6f1f3271720fffd9f82827f593737e1af7f833.diff LOG: [lldb] [test] Skip new NonStop tests on Windows Added: Modified: lldb/test/API/tools/lldb-server/TestNonStop.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestNonStop.py b/lldb/test/API/tools/lldb-server/TestNonStop.py index 30dec7f115e1..e4367f6ec9ff 100644 --- a/lldb/test/API/tools/lldb-server/TestNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestNonStop.py @@ -196,6 +196,7 @@ def test_multiple_c(self): def test_multiple_s(self): self.multiple_resume_test("s") +@skipIfWindows @add_test_categories(["llgs"]) def test_multiple_vCont(self): self.build() @@ -286,10 +287,12 @@ def vCont_then_partial_stop_test(self, run_both): ], True) self.expect_gdbremote_sequence() +@skipIfWindows @add_test_categories(["llgs"]) def test_vCont_then_partial_stop(self): self.vCont_then_partial_stop_test(False) +@skipIfWindows @add_test_categories(["llgs"]) def test_vCont_then_partial_stop_run_both(self): self.vCont_then_partial_stop_test(True) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] eb43e43 - Reland "[lldb] [llgs] Fix multi-resume bugs with nonstop mode"
Author: Michał Górny Date: 2022-07-15T15:24:00+02:00 New Revision: eb43e43bb5b2d19e14309e120cb8e66136ae7c82 URL: https://github.com/llvm/llvm-project/commit/eb43e43bb5b2d19e14309e120cb8e66136ae7c82 DIFF: https://github.com/llvm/llvm-project/commit/eb43e43bb5b2d19e14309e120cb8e66136ae7c82.diff LOG: Reland "[lldb] [llgs] Fix multi-resume bugs with nonstop mode" Improve handling of multiple successive continue packets in non-stop mode. More specifically: 1. Explicitly send error response (instead of crashing on assertion) if the user attempts to resume the same process twice. Since we do not support thread-level non-stop mode, one needs to always stop the process explicitly before resuming another thread set. 2. Actually stop the process if "vCont;t" is delivered to a running process. Similarly, we only support stopping all the running threads simultaneously (via -1) and return an error in any other case. With this patch, running multiple processes simultaneously is still unsupported. The patch also employs a hack to avoid enabling stdio forwarding on "vCont;t" packet. Both of these issues are addressed by followup patches. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128710 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/test/API/tools/lldb-server/TestNonStop.py lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index a2ea53b0e8e19..8edb49f06a334 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1512,6 +1512,30 @@ GDBRemoteCommunicationServerLLGS::Handle_QListThreadsInStopReply( return SendOKResponse(); } +GDBRemoteCommunication::PacketResult +GDBRemoteCommunicationServerLLGS::ResumeProcess( +NativeProcessProtocol , const ResumeActionList ) { + Log *log = GetLog(LLDBLog::Process | LLDBLog::Thread); + + // In non-stop protocol mode, the process could be running already. + // We do not support resuming threads independently, so just error out. + if (!process.CanResume()) { +LLDB_LOG(log, "process {0} cannot be resumed (state={1})", process.GetID(), + process.GetState()); +return SendErrorResponse(0x37); + } + + Status error = process.Resume(actions); + if (error.Fail()) { +LLDB_LOG(log, "process {0} failed to resume: {1}", process.GetID(), error); +return SendErrorResponse(GDBRemoteServerError::eErrorResume); + } + + LLDB_LOG(log, "process {0} resumed", process.GetID()); + + return PacketResult::Success; +} + GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote ) { Log *log = GetLog(LLDBLog::Process | LLDBLog::Thread); @@ -1547,6 +1571,14 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote ) { packet, "unexpected content after $C{signal-number}"); } + // In non-stop protocol mode, the process could be running already. + // We do not support resuming threads independently, so just error out. + if (!m_continue_process->CanResume()) { +LLDB_LOG(log, "process cannot be resumed (state={0})", + m_continue_process->GetState()); +return SendErrorResponse(0x37); + } + ResumeActionList resume_actions(StateType::eStateRunning, LLDB_INVALID_SIGNAL_NUMBER); Status error; @@ -1580,14 +1612,11 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote ) { } } - // Resume the threads. - error = m_continue_process->Resume(resume_actions); - if (error.Fail()) { -LLDB_LOG(log, "failed to resume threads for process {0}: {1}", - m_continue_process->GetID(), error); - -return SendErrorResponse(0x38); - } + // NB: this checks CanResume() twice but using a single code path for + // resuming still seems worth it. + PacketResult resume_res = ResumeProcess(*m_continue_process, resume_actions); + if (resume_res != PacketResult::Success) +return resume_res; // Don't send an "OK" packet, except in non-stop mode; // otherwise, the response is the stopped/exited message. @@ -1622,14 +1651,9 @@ GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote ) { ResumeActionList actions(StateType::eStateRunning, LLDB_INVALID_SIGNAL_NUMBER); - Status error = m_continue_process->Resume(actions); - if (error.Fail()) { -LLDB_LOG(log, "c failed for process {0}: {1}", m_continue_process->GetID(), - error); -
[Lldb-commits] [lldb] 7a2b09b - Revert "[lldb] [llgs] Fix multi-resume bugs with nonstop mode"
Author: Michał Górny Date: 2022-07-15T13:43:34+02:00 New Revision: 7a2b09b4798dbd5ec69e934b595eab5afddf33c5 URL: https://github.com/llvm/llvm-project/commit/7a2b09b4798dbd5ec69e934b595eab5afddf33c5 DIFF: https://github.com/llvm/llvm-project/commit/7a2b09b4798dbd5ec69e934b595eab5afddf33c5.diff LOG: Revert "[lldb] [llgs] Fix multi-resume bugs with nonstop mode" This reverts commit f8605da8758fbae16410e4ed5493a39429fd73ec. This is causing buildbot failures and now I see that I have not updated the tests to use "stop" instead of "trap". Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/test/API/tools/lldb-server/TestNonStop.py lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 8edb49f06a334..a2ea53b0e8e19 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1512,30 +1512,6 @@ GDBRemoteCommunicationServerLLGS::Handle_QListThreadsInStopReply( return SendOKResponse(); } -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerLLGS::ResumeProcess( -NativeProcessProtocol , const ResumeActionList ) { - Log *log = GetLog(LLDBLog::Process | LLDBLog::Thread); - - // In non-stop protocol mode, the process could be running already. - // We do not support resuming threads independently, so just error out. - if (!process.CanResume()) { -LLDB_LOG(log, "process {0} cannot be resumed (state={1})", process.GetID(), - process.GetState()); -return SendErrorResponse(0x37); - } - - Status error = process.Resume(actions); - if (error.Fail()) { -LLDB_LOG(log, "process {0} failed to resume: {1}", process.GetID(), error); -return SendErrorResponse(GDBRemoteServerError::eErrorResume); - } - - LLDB_LOG(log, "process {0} resumed", process.GetID()); - - return PacketResult::Success; -} - GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote ) { Log *log = GetLog(LLDBLog::Process | LLDBLog::Thread); @@ -1571,14 +1547,6 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote ) { packet, "unexpected content after $C{signal-number}"); } - // In non-stop protocol mode, the process could be running already. - // We do not support resuming threads independently, so just error out. - if (!m_continue_process->CanResume()) { -LLDB_LOG(log, "process cannot be resumed (state={0})", - m_continue_process->GetState()); -return SendErrorResponse(0x37); - } - ResumeActionList resume_actions(StateType::eStateRunning, LLDB_INVALID_SIGNAL_NUMBER); Status error; @@ -1612,11 +1580,14 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote ) { } } - // NB: this checks CanResume() twice but using a single code path for - // resuming still seems worth it. - PacketResult resume_res = ResumeProcess(*m_continue_process, resume_actions); - if (resume_res != PacketResult::Success) -return resume_res; + // Resume the threads. + error = m_continue_process->Resume(resume_actions); + if (error.Fail()) { +LLDB_LOG(log, "failed to resume threads for process {0}: {1}", + m_continue_process->GetID(), error); + +return SendErrorResponse(0x38); + } // Don't send an "OK" packet, except in non-stop mode; // otherwise, the response is the stopped/exited message. @@ -1651,9 +1622,14 @@ GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote ) { ResumeActionList actions(StateType::eStateRunning, LLDB_INVALID_SIGNAL_NUMBER); - PacketResult resume_res = ResumeProcess(*m_continue_process, actions); - if (resume_res != PacketResult::Success) -return resume_res; + Status error = m_continue_process->Resume(actions); + if (error.Fail()) { +LLDB_LOG(log, "c failed for process {0}: {1}", m_continue_process->GetID(), + error); +return SendErrorResponse(GDBRemoteServerError::eErrorResume); + } + + LLDB_LOG(log, "continued process {0}", m_continue_process->GetID()); return SendContinueSuccessResponse(); } @@ -1667,18 +1643,6 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont_actions( return SendPacketNoLock(response.GetString()); } -static bool ResumeActionListStopsAllThreads(ResumeActionList ) { - // We're doing a stop-all if and only if our only action is a "t" for all - // threads. - if (const ResumeAction *default_action = -
[Lldb-commits] [lldb] f8605da - [lldb] [llgs] Fix multi-resume bugs with nonstop mode
Author: Michał Górny Date: 2022-07-15T13:01:39+02:00 New Revision: f8605da8758fbae16410e4ed5493a39429fd73ec URL: https://github.com/llvm/llvm-project/commit/f8605da8758fbae16410e4ed5493a39429fd73ec DIFF: https://github.com/llvm/llvm-project/commit/f8605da8758fbae16410e4ed5493a39429fd73ec.diff LOG: [lldb] [llgs] Fix multi-resume bugs with nonstop mode Improve handling of multiple successive continue packets in non-stop mode. More specifically: 1. Explicitly send error response (instead of crashing on assertion) if the user attempts to resume the same process twice. Since we do not support thread-level non-stop mode, one needs to always stop the process explicitly before resuming another thread set. 2. Actually stop the process if "vCont;t" is delivered to a running process. Similarly, we only support stopping all the running threads simultaneously (via -1) and return an error in any other case. With this patch, running multiple processes simultaneously is still unsupported. The patch also employs a hack to avoid enabling stdio forwarding on "vCont;t" packet. Both of these issues are addressed by followup patches. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128710 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/test/API/tools/lldb-server/TestNonStop.py lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index a2ea53b0e8e19..8edb49f06a334 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1512,6 +1512,30 @@ GDBRemoteCommunicationServerLLGS::Handle_QListThreadsInStopReply( return SendOKResponse(); } +GDBRemoteCommunication::PacketResult +GDBRemoteCommunicationServerLLGS::ResumeProcess( +NativeProcessProtocol , const ResumeActionList ) { + Log *log = GetLog(LLDBLog::Process | LLDBLog::Thread); + + // In non-stop protocol mode, the process could be running already. + // We do not support resuming threads independently, so just error out. + if (!process.CanResume()) { +LLDB_LOG(log, "process {0} cannot be resumed (state={1})", process.GetID(), + process.GetState()); +return SendErrorResponse(0x37); + } + + Status error = process.Resume(actions); + if (error.Fail()) { +LLDB_LOG(log, "process {0} failed to resume: {1}", process.GetID(), error); +return SendErrorResponse(GDBRemoteServerError::eErrorResume); + } + + LLDB_LOG(log, "process {0} resumed", process.GetID()); + + return PacketResult::Success; +} + GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote ) { Log *log = GetLog(LLDBLog::Process | LLDBLog::Thread); @@ -1547,6 +1571,14 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote ) { packet, "unexpected content after $C{signal-number}"); } + // In non-stop protocol mode, the process could be running already. + // We do not support resuming threads independently, so just error out. + if (!m_continue_process->CanResume()) { +LLDB_LOG(log, "process cannot be resumed (state={0})", + m_continue_process->GetState()); +return SendErrorResponse(0x37); + } + ResumeActionList resume_actions(StateType::eStateRunning, LLDB_INVALID_SIGNAL_NUMBER); Status error; @@ -1580,14 +1612,11 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote ) { } } - // Resume the threads. - error = m_continue_process->Resume(resume_actions); - if (error.Fail()) { -LLDB_LOG(log, "failed to resume threads for process {0}: {1}", - m_continue_process->GetID(), error); - -return SendErrorResponse(0x38); - } + // NB: this checks CanResume() twice but using a single code path for + // resuming still seems worth it. + PacketResult resume_res = ResumeProcess(*m_continue_process, resume_actions); + if (resume_res != PacketResult::Success) +return resume_res; // Don't send an "OK" packet, except in non-stop mode; // otherwise, the response is the stopped/exited message. @@ -1622,14 +1651,9 @@ GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote ) { ResumeActionList actions(StateType::eStateRunning, LLDB_INVALID_SIGNAL_NUMBER); - Status error = m_continue_process->Resume(actions); - if (error.Fail()) { -LLDB_LOG(log, "c failed for process {0}: {1}", m_continue_process->GetID(), - error); -return
[Lldb-commits] [lldb] 06b3f27 - [lldb] [llgs] Remove not-really-used m_inferior_prev_state
Author: Michał Górny Date: 2022-07-14T19:25:54+02:00 New Revision: 06b3f27fedd5a26ad571c093ccf47d0c11b1e913 URL: https://github.com/llvm/llvm-project/commit/06b3f27fedd5a26ad571c093ccf47d0c11b1e913 DIFF: https://github.com/llvm/llvm-project/commit/06b3f27fedd5a26ad571c093ccf47d0c11b1e913.diff LOG: [lldb] [llgs] Remove not-really-used m_inferior_prev_state Remove m_inferior_prev_state that's not suitable for multiprocess debugging and that does not seem to be really used at all. The only use of the variable right now is to "prevent" sending the stop reason after attach/launch. However, this code is never actually run since none of the process plugins actually use eStateLaunching or eStateAttaching. Through adding an assert, I've confirmed that it's never hit in any of the LLDB tests or while attaching/launching debugged process via lldb-server and via lldb CLI. Differential Revision: https://reviews.llvm.org/D128878 Sponsored by: The FreeBSD Foundation Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 7ddb4c80e16d..a2ea53b0e8e1 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1077,23 +1077,13 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped( Log *log = GetLog(LLDBLog::Process); LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); - // Send the stop reason unless this is the stop after the launch or attach. - switch (m_inferior_prev_state) { - case eStateLaunching: - case eStateAttaching: -// Don't send anything per debugserver behavior. -break; - default: -// In all other cases, send the stop reason. -PacketResult result = SendStopReasonForState( -*process, StateType::eStateStopped, /*force_synchronous=*/false); -if (result != PacketResult::Success) { - LLDB_LOGF(log, -"GDBRemoteCommunicationServerLLGS::%s failed to send stop " -"notification for PID %" PRIu64 ", state: eStateExited", -__FUNCTION__, process->GetID()); -} -break; + PacketResult result = SendStopReasonForState( + *process, StateType::eStateStopped, /*force_synchronous=*/false); + if (result != PacketResult::Success) { +LLDB_LOGF(log, + "GDBRemoteCommunicationServerLLGS::%s failed to send stop " + "notification for PID %" PRIu64 ", state: eStateExited", + __FUNCTION__, process->GetID()); } } @@ -1138,9 +1128,6 @@ void GDBRemoteCommunicationServerLLGS::ProcessStateChanged( } break; } - - // Remember the previous state reported to us. - m_inferior_prev_state = state; } void GDBRemoteCommunicationServerLLGS::DidExec(NativeProcessProtocol *process) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h index cdbda0e9ca8a..ebd656687da9 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -110,7 +110,6 @@ class GDBRemoteCommunicationServerLLGS Communication m_stdio_communication; MainLoop::ReadHandleUP m_stdio_handle_up; - lldb::StateType m_inferior_prev_state = lldb::StateType::eStateInvalid; llvm::StringMap> m_xfer_buffer_map; std::mutex m_saved_registers_mutex; std::unordered_map m_saved_registers_map; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 355c791 - [lldb] [llgs] Convert m_debugged_processes into a map of structs
Author: Michał Górny Date: 2022-07-14T15:32:19+02:00 New Revision: 355c7916336fb4922946a8cfc174dbdb514dddb5 URL: https://github.com/llvm/llvm-project/commit/355c7916336fb4922946a8cfc174dbdb514dddb5 DIFF: https://github.com/llvm/llvm-project/commit/355c7916336fb4922946a8cfc174dbdb514dddb5.diff LOG: [lldb] [llgs] Convert m_debugged_processes into a map of structs Convert the m_debugged_processes map from NativeProcessProtocol pointers to structs, and combine the additional set(s) holding the additional process properties into a flag field inside this struct. This is desirable since there are more properties to come and having a single structure with all information should be cleaner and more efficient than using multiple sets for that. Suggested by Pavel Labath in D128893. Differential Revision: https://reviews.llvm.org/D129652 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 63174ef55219..7ddb4c80e16d 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -290,7 +290,9 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() { if (!process_or) return Status(process_or.takeError()); m_continue_process = m_current_process = process_or->get(); -m_debugged_processes[m_current_process->GetID()] = std::move(*process_or); +m_debugged_processes.emplace( +m_current_process->GetID(), +DebuggedProcess{std::move(*process_or), DebuggedProcess::Flag{}}); } SetEnabledExtensions(*m_current_process); @@ -361,7 +363,9 @@ Status GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) { return status; } m_continue_process = m_current_process = process_or->get(); - m_debugged_processes[m_current_process->GetID()] = std::move(*process_or); + m_debugged_processes.emplace( + m_current_process->GetID(), + DebuggedProcess{std::move(*process_or), DebuggedProcess::Flag{}}); SetEnabledExtensions(*m_current_process); // Setup stdout/stderr mapping from inferior. @@ -489,12 +493,14 @@ GDBRemoteCommunicationServerLLGS::SendWResponse( *wait_status); // If the process was killed through vKill, return "OK". - if (m_vkilled_processes.find(process->GetID()) != m_vkilled_processes.end()) + if (bool(m_debugged_processes.at(process->GetID()).flags & + DebuggedProcess::Flag::vkilled)) return SendOKResponse(); StreamGDBRemote response; response.Format("{0:g}", *wait_status); - if (bool(m_extensions_supported & NativeProcessProtocol::Extension::multiprocess)) + if (bool(m_extensions_supported & + NativeProcessProtocol::Extension::multiprocess)) response.Format(";process:{0:x-}", process->GetID()); if (m_non_stop) return SendNotificationPacketNoLock("Stop", m_stop_notification_queue, @@ -1045,14 +1051,14 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited( lldb::pid_t pid = process->GetID(); m_mainloop.AddPendingCallback([this, pid](MainLoopBase ) { -m_debugged_processes.erase(pid); -auto vkill_it = m_vkilled_processes.find(pid); -if (vkill_it != m_vkilled_processes.end()) - m_vkilled_processes.erase(vkill_it); +auto find_it = m_debugged_processes.find(pid); +assert(find_it != m_debugged_processes.end()); +bool vkilled = bool(find_it->second.flags & DebuggedProcess::Flag::vkilled); +m_debugged_processes.erase(find_it); // Terminate the main loop only if vKill has not been used. // When running in non-stop mode, wait for the vStopped to clear // the notification queue. -else if (m_debugged_processes.empty() && !m_non_stop) { +if (m_debugged_processes.empty() && !m_non_stop && !vkilled) { // Close the pipe to the inferior terminal i/o if we launched it and set // one up. MaybeCloseInferiorTerminalConnection(); @@ -1147,7 +1153,9 @@ void GDBRemoteCommunicationServerLLGS::NewSubprocess( lldb::pid_t child_pid = child_process->GetID(); assert(child_pid != LLDB_INVALID_PROCESS_ID); assert(m_debugged_processes.find(child_pid) == m_debugged_processes.end()); - m_debugged_processes[child_pid] = std::move(child_process); + m_debugged_processes.emplace( + child_pid, + DebuggedProcess{std::move(child_process), DebuggedProcess::Flag{}}); } void GDBRemoteCommunicationServerLLGS::DataAvailableCallback() { @@ -1432,7 +1440,7 @@ GDBRemoteCommunicationServerLLGS::Handle_k(StringExtractorGDBRemote ) { for (auto it = m_debugged_processes.begin(); it
[Lldb-commits] [lldb] c164efb - [lldb] [gdb-remote] Remove stray GetSupportsThreadSuffix() method (NFC)
Author: Michał Górny Date: 2022-07-14T12:18:17+02:00 New Revision: c164efb0064682893fc37d6c07e1e000861d7879 URL: https://github.com/llvm/llvm-project/commit/c164efb0064682893fc37d6c07e1e000861d7879 DIFF: https://github.com/llvm/llvm-project/commit/c164efb0064682893fc37d6c07e1e000861d7879.diff LOG: [lldb] [gdb-remote] Remove stray GetSupportsThreadSuffix() method (NFC) Remove stray GDBRemoteCommunicationClient::GetSupportsThreadSuffix() method that is not implemented nor used anywhere. Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index 58ed22187747..d367f75cee0e 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -254,8 +254,6 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase { lldb::addr_t GetShlibInfoAddr(); - bool GetSupportsThreadSuffix(); - bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo _info); uint32_t FindProcesses(const ProcessInstanceInfoMatch _match_info, ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 9790406 - Reland "[lldb] [test] Improve stability of llgs vCont-threads tests"
Author: Michał Górny Date: 2022-07-11T18:05:14+02:00 New Revision: 9790406a9226e112e75eeeac1c326cff9b570264 URL: https://github.com/llvm/llvm-project/commit/9790406a9226e112e75eeeac1c326cff9b570264 DIFF: https://github.com/llvm/llvm-project/commit/9790406a9226e112e75eeeac1c326cff9b570264.diff LOG: Reland "[lldb] [test] Improve stability of llgs vCont-threads tests" Perform a major refactoring of vCont-threads tests in order to attempt to improve their stability and performance. Split test_vCont_run_subset_of_threads() into smaller test cases, and split the whole suite into two files: one for signal-related tests, the running-subset-of tests. Eliminate output_match checks entirely, as they are fragile to fragmentation of output. Instead, for the initial thread list capture raise an explicit SIGINT from inside the test program, and for the remaining output let the test program run until exit, and check all the captured output afterwards. For resume tests, capture the LLDB's thread view before and after starting new threads in order to determine the IDs corresponding to subthreads rather than relying on program output for that. Add a mutex for output to guarantee serialization. A barrier is used to guarantee that all threads start before SIGINT, and an atomic bool is used to delay prints from happening until after SIGINT. Call std::this_thread::yield() to reduce the risk of one of the threads not being run. This fixes the test hangs on FreeBSD. Hopefully, it will also fix all the flakiness on buildbots. Thanks to Pavel Labath for figuring out why the original version did not work on Debian. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D129012 Added: lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py lldb/test/API/tools/lldb-server/vCont-threads/TestSignal.py Modified: lldb/test/API/tools/lldb-server/vCont-threads/main.cpp Removed: lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py diff --git a/lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py b/lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py new file mode 100644 index 0..2cc60d3d0a5c0 --- /dev/null +++ b/lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py @@ -0,0 +1,128 @@ +import re + +import gdbremote_testcase +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class TestPartialResume(gdbremote_testcase.GdbRemoteTestCaseBase): +THREAD_MATCH_RE = re.compile(r"thread ([0-9a-f]+) running") + +def start_vCont_run_subset_of_threads_test(self): +self.build() +self.set_inferior_startup_launch() + +procs = self.prep_debug_monitor_and_inferior(inferior_args=["3"]) +# grab the main thread id +self.add_threadinfo_collection_packets() +main_thread = self.parse_threadinfo_packets( +self.expect_gdbremote_sequence()) +self.assertEqual(len(main_thread), 1) +self.reset_test_sequence() + +# run until threads start, then grab full thread list +self.test_sequence.add_log_lines([ +"read packet: $c#63", +{"direction": "send", "regex": "[$]T.*;reason:signal.*"}, +], True) +self.add_threadinfo_collection_packets() + +all_threads = self.parse_threadinfo_packets( +self.expect_gdbremote_sequence()) +self.assertEqual(len(all_threads), 4) +self.assertIn(main_thread[0], all_threads) +self.reset_test_sequence() + +all_subthreads = set(all_threads) - set(main_thread) +self.assertEqual(len(all_subthreads), 3) + +return (main_thread[0], list(all_subthreads)) + +def continue_and_get_threads_running(self, main_thread, vCont_req): +self.test_sequence.add_log_lines( +["read packet: $vCont;c:{:x};{}#00".format(main_thread, vCont_req), + "send packet: $W00#00", + ], True) +exp = self.expect_gdbremote_sequence() +self.reset_test_sequence() +found = set() +for line in exp["O_content"].decode().splitlines(): +m = self.THREAD_MATCH_RE.match(line) +if m is not None: +found.add(int(m.group(1), 16)) +return found + +@skipIfWindows +@add_test_categories(["llgs"]) +def test_vCont_cxcx(self): +main_thread, all_subthreads_list = ( +self.start_vCont_run_subset_of_threads_test()) +# resume two threads explicitly, stop the third one implicitly +self.assertEqual( +self.continue_and_get_threads_running( +main_thread, +"c:{:x};c:{:x}".format(*all_subthreads_list[:2])), +set(all_subthreads_list[:2])) + +@skipIfWindows +@add_test_categories(["llgs"]) +def
[Lldb-commits] [lldb] fad93cd - Revert "[lldb] [test] Improve stability of llgs vCont-threads tests"
Author: Michał Górny Date: 2022-07-07T17:01:43+02:00 New Revision: fad93cd6821992baf0e1b5c45c1606aa5fde2938 URL: https://github.com/llvm/llvm-project/commit/fad93cd6821992baf0e1b5c45c1606aa5fde2938 DIFF: https://github.com/llvm/llvm-project/commit/fad93cd6821992baf0e1b5c45c1606aa5fde2938.diff LOG: Revert "[lldb] [test] Improve stability of llgs vCont-threads tests" This reverts commit 86e472317c8fd9309b76c32ca55fcdeaf63f853b. It breaks Debian buildbot, for some reason. Added: lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py Modified: lldb/test/API/tools/lldb-server/vCont-threads/main.cpp Removed: lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py lldb/test/API/tools/lldb-server/vCont-threads/TestSignal.py diff --git a/lldb/test/API/tools/lldb-server/vCont-threads/TestSignal.py b/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py similarity index 71% rename from lldb/test/API/tools/lldb-server/vCont-threads/TestSignal.py rename to lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py index 6dde4f9555cf3..606875ed56213 100644 --- a/lldb/test/API/tools/lldb-server/vCont-threads/TestSignal.py +++ b/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py @@ -1,18 +1,23 @@ +import json import re +import time import gdbremote_testcase from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil +class TestGdbRemote_vContThreads(gdbremote_testcase.GdbRemoteTestCaseBase): -class TestSignal(gdbremote_testcase.GdbRemoteTestCaseBase): def start_threads(self, num): procs = self.prep_debug_monitor_and_inferior(inferior_args=[str(num)]) +# start the process and wait for output self.test_sequence.add_log_lines([ "read packet: $c#63", -{"direction": "send", "regex": "[$]T.*;reason:signal.*"}, +{"type": "output_match", "regex": r".*@started\r\n.*"}, ], True) +# then interrupt it +self.add_interrupt_packets() self.add_threadinfo_collection_packets() context = self.expect_gdbremote_sequence() @@ -24,21 +29,22 @@ def start_threads(self, num): self.reset_test_sequence() return threads -SIGNAL_MATCH_RE = re.compile(r"received SIGUSR1 on thread id: ([0-9a-f]+)") - def send_and_check_signal(self, vCont_data, threads): self.test_sequence.add_log_lines([ "read packet: $vCont;{0}#00".format(vCont_data), -"send packet: $W00#00", +{"type": "output_match", + "regex": len(threads) * + r".*received SIGUSR1 on thread id: ([0-9a-f]+)\r\n.*", + "capture": dict((i, "tid{0}".format(i)) for i + in range(1, len(threads)+1)), + }, ], True) -exp = self.expect_gdbremote_sequence() -self.reset_test_sequence() -tids = [] -for line in exp["O_content"].decode().splitlines(): -m = self.SIGNAL_MATCH_RE.match(line) -if m is not None: -tids.append(int(m.group(1), 16)) -self.assertEqual(sorted(tids), sorted(threads)) + +context = self.expect_gdbremote_sequence() +self.assertIsNotNone(context) +tids = sorted(int(context["tid{0}".format(x)], 16) + for x in range(1, len(threads)+1)) +self.assertEqual(tids, sorted(threads)) def get_pid(self): self.add_process_info_collection_packets() @@ -236,3 +242,72 @@ def test_signal_two_signals(self): context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) + +THREAD_MATCH_RE = re.compile(r"thread ([0-9a-f]+) running") + +def continue_and_get_threads_running(self, continue_packet): +self.test_sequence.add_log_lines( +["read packet: ${}#00".format(continue_packet), + ], True) +self.expect_gdbremote_sequence() +self.reset_test_sequence() +time.sleep(1) +self.add_interrupt_packets() +exp = self.expect_gdbremote_sequence() +found = set() +for line in exp["O_content"].decode().splitlines(): +m = self.THREAD_MATCH_RE.match(line) +if m is not None: +found.add(int(m.group(1), 16)) +return found + +@skipIfWindows +@add_test_categories(["llgs"]) +def test_vCont_run_subset_of_threads(self): +self.build() +self.set_inferior_startup_launch() + +threads = set(self.start_threads(3)) +all_subthreads = self.continue_and_get_threads_running("c") +all_subthreads_list = list(all_subthreads) +self.assertEqual(len(all_subthreads), 3) +self.assertEqual(threads & all_subthreads, all_subthreads) +
[Lldb-commits] [lldb] 86e4723 - [lldb] [test] Improve stability of llgs vCont-threads tests
Author: Michał Górny Date: 2022-07-07T16:33:55+02:00 New Revision: 86e472317c8fd9309b76c32ca55fcdeaf63f853b URL: https://github.com/llvm/llvm-project/commit/86e472317c8fd9309b76c32ca55fcdeaf63f853b DIFF: https://github.com/llvm/llvm-project/commit/86e472317c8fd9309b76c32ca55fcdeaf63f853b.diff LOG: [lldb] [test] Improve stability of llgs vCont-threads tests Perform a major refactoring of vCont-threads tests in order to attempt to improve their stability and performance. Split test_vCont_run_subset_of_threads() into smaller test cases, and split the whole suite into two files: one for signal-related tests, the running-subset-of tests. Eliminate output_match checks entirely, as they are fragile to fragmentation of output. Instead, for the initial thread list capture raise an explicit SIGSTOP from inside the test program, and for the remaining output let the test program run until exit, and check all the captured output afterwards. For resume tests, capture the LLDB's thread view before and after starting new threads in order to determine the IDs corresponding to subthreads rather than relying on program output for that. Add a mutex for output to guarantee serialization. A barrier is used to guarantee that all threads start before SIGSTOP, and an atomic bool is used to delay prints from happening until after SIGSTOP. Call std::this_thread::yield() to reduce the risk of one of the threads not being run. This fixes the test hangs on FreeBSD. Hopefully, it will also fix all the flakiness on buildbots. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D129012 Added: lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py lldb/test/API/tools/lldb-server/vCont-threads/TestSignal.py Modified: lldb/test/API/tools/lldb-server/vCont-threads/main.cpp Removed: lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py diff --git a/lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py b/lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py new file mode 100644 index 0..2cc60d3d0a5c0 --- /dev/null +++ b/lldb/test/API/tools/lldb-server/vCont-threads/TestPartialResume.py @@ -0,0 +1,128 @@ +import re + +import gdbremote_testcase +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class TestPartialResume(gdbremote_testcase.GdbRemoteTestCaseBase): +THREAD_MATCH_RE = re.compile(r"thread ([0-9a-f]+) running") + +def start_vCont_run_subset_of_threads_test(self): +self.build() +self.set_inferior_startup_launch() + +procs = self.prep_debug_monitor_and_inferior(inferior_args=["3"]) +# grab the main thread id +self.add_threadinfo_collection_packets() +main_thread = self.parse_threadinfo_packets( +self.expect_gdbremote_sequence()) +self.assertEqual(len(main_thread), 1) +self.reset_test_sequence() + +# run until threads start, then grab full thread list +self.test_sequence.add_log_lines([ +"read packet: $c#63", +{"direction": "send", "regex": "[$]T.*;reason:signal.*"}, +], True) +self.add_threadinfo_collection_packets() + +all_threads = self.parse_threadinfo_packets( +self.expect_gdbremote_sequence()) +self.assertEqual(len(all_threads), 4) +self.assertIn(main_thread[0], all_threads) +self.reset_test_sequence() + +all_subthreads = set(all_threads) - set(main_thread) +self.assertEqual(len(all_subthreads), 3) + +return (main_thread[0], list(all_subthreads)) + +def continue_and_get_threads_running(self, main_thread, vCont_req): +self.test_sequence.add_log_lines( +["read packet: $vCont;c:{:x};{}#00".format(main_thread, vCont_req), + "send packet: $W00#00", + ], True) +exp = self.expect_gdbremote_sequence() +self.reset_test_sequence() +found = set() +for line in exp["O_content"].decode().splitlines(): +m = self.THREAD_MATCH_RE.match(line) +if m is not None: +found.add(int(m.group(1), 16)) +return found + +@skipIfWindows +@add_test_categories(["llgs"]) +def test_vCont_cxcx(self): +main_thread, all_subthreads_list = ( +self.start_vCont_run_subset_of_threads_test()) +# resume two threads explicitly, stop the third one implicitly +self.assertEqual( +self.continue_and_get_threads_running( +main_thread, +"c:{:x};c:{:x}".format(*all_subthreads_list[:2])), +set(all_subthreads_list[:2])) + +@skipIfWindows +@add_test_categories(["llgs"]) +def test_vCont_cxcxt(self): +main_thread, all_subthreads_list = ( +
[Lldb-commits] [lldb] 4a95861 - [lldb] [test] Avoid relying on signos in other fork tests
Author: Michał Górny Date: 2022-06-29T17:48:36+02:00 New Revision: 4a95861d7394da7e7f33ff325c3b28159cb6aa77 URL: https://github.com/llvm/llvm-project/commit/4a95861d7394da7e7f33ff325c3b28159cb6aa77 DIFF: https://github.com/llvm/llvm-project/commit/4a95861d7394da7e7f33ff325c3b28159cb6aa77.diff LOG: [lldb] [test] Avoid relying on signos in other fork tests Sponsored by: The FreeBSD Foundation Added: Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py index bd9c3843ddfe..1a3cc4a0350f 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py @@ -2,9 +2,10 @@ class GdbRemoteForkTestBase(gdbremote_testcase.GdbRemoteTestCaseBase): -fork_regex = ("[$]T05thread:p([0-9a-f]+)[.]([0-9a-f]+);.*" +fork_regex = ("[$]T[0-9a-fA-F]{{2}}thread:p([0-9a-f]+)[.]([0-9a-f]+);.*" "{}:p([0-9a-f]+)[.]([0-9a-f]+).*") -fork_regex_nonstop = ("%Stop:T05thread:p([0-9a-f]+)[.]([0-9a-f]+);.*" +fork_regex_nonstop = ("%Stop:T[0-9a-fA-F]{{2}}" + "thread:p([0-9a-f]+)[.]([0-9a-f]+);.*" "{}:p([0-9a-f]+)[.]([0-9a-f]+).*") fork_capture = {1: "parent_pid", 2: "parent_tid", 3: "child_pid", 4: "child_tid"} diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 3b0338075a05..0c169de3f4d0 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -38,8 +38,8 @@ def test_vfork(self): self.test_sequence.add_log_lines([ "read packet: $c#00", {"direction": "send", - "regex": r"[$]T05thread:p{}[.]{}.*vforkdone.*".format(parent_pid, - parent_tid), + "regex": r"[$]T[0-9a-fA-F]{{2}}thread:p{}[.]{}.*vforkdone.*" + .format(parent_pid, parent_tid), }, "read packet: $c#00", "send packet: $W00;process:{}#00".format(parent_pid), diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py index 5b1a35408d3e..764f238a51ee 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py @@ -15,8 +15,8 @@ def test_vfork_nonstop(self): "read packet: $c#00", "send packet: $OK#00", {"direction": "send", - "regex": r"%Stop:T05thread:p{}[.]{}.*vforkdone.*".format( - parent_pid, parent_tid), + "regex": r"%Stop:T[0-9a-fA-F]{{2}}thread:p{}[.]{}.*vforkdone.*" + .format(parent_pid, parent_tid), }, "read packet: $vStopped#00", "send packet: $OK#00", ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] e60ed24 - [lldb] [test] Un-XFAIL fork tests on arm as well
Author: Michał Górny Date: 2022-06-29T16:05:12+02:00 New Revision: e60ed2401b22074e02779081ca16fa93bd4cf244 URL: https://github.com/llvm/llvm-project/commit/e60ed2401b22074e02779081ca16fa93bd4cf244 DIFF: https://github.com/llvm/llvm-project/commit/e60ed2401b22074e02779081ca16fa93bd4cf244.diff LOG: [lldb] [test] Un-XFAIL fork tests on arm as well Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index fa5b116438c5..3b0338075a05 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -153,54 +153,44 @@ def test_vkill_parent(self): def test_vkill_both(self): self.vkill_test(kill_parent=True, kill_child=True) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_c_parent(self): self.resume_one_test(run_order=["parent", "parent"]) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_c_child(self): self.resume_one_test(run_order=["child", "child"]) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_c_parent_then_child(self): self.resume_one_test(run_order=["parent", "parent", "child", "child"]) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_c_child_then_parent(self): self.resume_one_test(run_order=["child", "child", "parent", "parent"]) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_c_interspersed(self): self.resume_one_test(run_order=["parent", "child", "parent", "child"]) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_vCont_parent(self): self.resume_one_test(run_order=["parent", "parent"], use_vCont=True) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_vCont_child(self): self.resume_one_test(run_order=["child", "child"], use_vCont=True) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_vCont_parent_then_child(self): self.resume_one_test(run_order=["parent", "parent", "child", "child"], use_vCont=True) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_vCont_child_then_parent(self): self.resume_one_test(run_order=["child", "child", "parent", "parent"], use_vCont=True) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_vCont_interspersed(self): self.resume_one_test(run_order=["parent", "child", "parent", "child"], @@ -241,7 +231,6 @@ def test_vCont_all_processes_implicit(self): ], True) self.expect_gdbremote_sequence() -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_threadinfo(self): parent_pid, parent_tid, child_pid, child_tid = ( @@ -287,7 +276,6 @@ def test_threadinfo(self): ], True) self.expect_gdbremote_sequence() -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_memory_read_write(self): self.build() @@ -375,7 +363,6 @@ def test_memory_read_write(self): self.assertEqual(data, name + "\0") self.reset_test_sequence() -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_register_read_write(self): parent_pid, parent_tid, child_pid, child_tid = ( @@ -472,7 +459,6 @@ def test_register_read_write(self): self.assertIsNotNone(data) self.assertEqual(data, old_val[1]) -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_qC(self): parent_pid, parent_tid, child_pid, child_tid = ( @@ -507,7 +493,6 @@ def test_qC(self): ], True) self.expect_gdbremote_sequence() -@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_T(self): parent_pid, parent_tid, child_pid, child_tid = ( diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py index 38f695956170..5b1a35408d3e 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py @@ -98,13 +98,11 @@ def test_kill_all_nonstop(self): def
[Lldb-commits] [lldb] 251165b - [lldb] [test] Use raise(SIGSTOP) instead of trap in fork tests
Author: Michał Górny Date: 2022-06-29T15:37:26+02:00 New Revision: 251165b2e48216f8fbeef1960711219afac406f4 URL: https://github.com/llvm/llvm-project/commit/251165b2e48216f8fbeef1960711219afac406f4 DIFF: https://github.com/llvm/llvm-project/commit/251165b2e48216f8fbeef1960711219afac406f4.diff LOG: [lldb] [test] Use raise(SIGSTOP) instead of trap in fork tests Replace the use of "trap" with a new "stop" command in fork tests, that maps to `raise(SIGSTOP)`. Since traps do not increment PC on some architectures (notably ARM), using traps would require special logic to increment it while testing. Using SIGSTOP avoids the problem and is probably more logical, given that the purpose of the "trap"s was to simply stop the inferior at a synchronization point. This fixes tests on AArch64 (and possibly ARM, I'll update XFAILs when it is confirmed by the buildbot). Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128780 Added: Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py lldb/test/API/tools/lldb-server/main.cpp Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py index 42833a15318f2..bd9c3843ddfe1 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py @@ -8,6 +8,8 @@ class GdbRemoteForkTestBase(gdbremote_testcase.GdbRemoteTestCaseBase): "{}:p([0-9a-f]+)[.]([0-9a-f]+).*") fork_capture = {1: "parent_pid", 2: "parent_tid", 3: "child_pid", 4: "child_tid"} +stop_regex_base = "T[0-9a-fA-F]{{2}}thread:p{}.{};.*reason:signal.*" +stop_regex = "^[$]" + stop_regex_base def start_fork_test(self, args, variant="fork", nonstop=False): self.build() @@ -149,14 +151,14 @@ def vkill_test(self, kill_parent=False, kill_child=False, nonstop=False): def resume_one_test(self, run_order, use_vCont=False, nonstop=False): parent_pid, parent_tid, child_pid, child_tid = ( -self.start_fork_test(["fork", "trap"], nonstop=nonstop)) +self.start_fork_test(["fork", "stop"], nonstop=nonstop)) parent_expect = [ -"T05thread:p{}.{};.*".format(parent_pid, parent_tid), +self.stop_regex_base.format(parent_pid, parent_tid), "W00;process:{}#.*".format(parent_pid), ] child_expect = [ -"T05thread:p{}.{};.*".format(child_pid, child_tid), +self.stop_regex_base.format(child_pid, child_tid), "W00;process:{}#.*".format(child_pid), ] diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 81be3c67399e3..fa5b116438c51 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -154,73 +154,53 @@ def test_vkill_both(self): self.vkill_test(kill_parent=True, kill_child=True) @expectedFailureAll(archs=["arm"]) # TODO -@expectedFailureAll(archs=["aarch64"], - bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_parent(self): self.resume_one_test(run_order=["parent", "parent"]) @expectedFailureAll(archs=["arm"]) # TODO -@expectedFailureAll(archs=["aarch64"], - bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_child(self): self.resume_one_test(run_order=["child", "child"]) @expectedFailureAll(archs=["arm"]) # TODO -@expectedFailureAll(archs=["aarch64"], - bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_parent_then_child(self): self.resume_one_test(run_order=["parent", "parent", "child", "child"]) @expectedFailureAll(archs=["arm"]) # TODO -@expectedFailureAll(archs=["aarch64"], - bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_child_then_parent(self): self.resume_one_test(run_order=["child", "child", "parent", "parent"]) @expectedFailureAll(archs=["arm"]) # TODO -@expectedFailureAll(archs=["aarch64"], - bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_interspersed(self): self.resume_one_test(run_order=["parent", "child", "parent",
[Lldb-commits] [lldb] 3c16fb3 - [lldb] [test] Fix variable overwrite in non-stop fork tests
Author: Michał Górny Date: 2022-06-29T13:34:50+02:00 New Revision: 3c16fb3ab34d51c0df9512c38093d1c5c8dd6e79 URL: https://github.com/llvm/llvm-project/commit/3c16fb3ab34d51c0df9512c38093d1c5c8dd6e79 DIFF: https://github.com/llvm/llvm-project/commit/3c16fb3ab34d51c0df9512c38093d1c5c8dd6e79.diff LOG: [lldb] [test] Fix variable overwrite in non-stop fork tests Thanks to Pavel Labath for noticing the mistake in: https://reviews.llvm.org/D128638#3618039 Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py index 6b5010da9b19..bd9484ff0903 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py @@ -92,8 +92,7 @@ def test_kill_all_nonstop(self): "send packet: $OK#00", ], True) self.expect_gdbremote_sequence() -self.assertEqual(set([ret["pid1"], ret["pid2"]]), - set([parent_pid, child_pid])) +self.assertEqual(set([pid1, pid2]), set([parent_pid, child_pid])) @add_test_categories(["fork"]) def test_vkill_both_nonstop(self): ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 7fc12da - [lldb] [test] Split TestGdbRemoteFork in two
Author: Michał Górny Date: 2022-06-29T06:57:38+02:00 New Revision: 7fc12da898e05e68ec59fbe852c4402378938efa URL: https://github.com/llvm/llvm-project/commit/7fc12da898e05e68ec59fbe852c4402378938efa DIFF: https://github.com/llvm/llvm-project/commit/7fc12da898e05e68ec59fbe852c4402378938efa.diff LOG: [lldb] [test] Split TestGdbRemoteFork in two Split the test that's gotten very long in two, in hope that it will resolve the arm/aarch64 buildbot failures. Even if it does not, it could help pinpointing where the problem lies. Sponsored by: The FreeBSD Foundation Added: lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py lldb/test/API/tools/lldb-server/TestGdbRemoteForkNonStop.py Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py new file mode 100644 index ..42833a15318f --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/fork_testbase.py @@ -0,0 +1,204 @@ +import gdbremote_testcase + + +class GdbRemoteForkTestBase(gdbremote_testcase.GdbRemoteTestCaseBase): +fork_regex = ("[$]T05thread:p([0-9a-f]+)[.]([0-9a-f]+);.*" + "{}:p([0-9a-f]+)[.]([0-9a-f]+).*") +fork_regex_nonstop = ("%Stop:T05thread:p([0-9a-f]+)[.]([0-9a-f]+);.*" + "{}:p([0-9a-f]+)[.]([0-9a-f]+).*") +fork_capture = {1: "parent_pid", 2: "parent_tid", +3: "child_pid", 4: "child_tid"} + +def start_fork_test(self, args, variant="fork", nonstop=False): +self.build() +self.prep_debug_monitor_and_inferior(inferior_args=args) +self.add_qSupported_packets(["multiprocess+", + "{}-events+".format(variant)]) +ret = self.expect_gdbremote_sequence() +self.assertIn("{}-events+".format(variant), ret["qSupported_response"]) +self.reset_test_sequence() + +# continue and expect fork +if nonstop: +self.test_sequence.add_log_lines([ +"read packet: $QNonStop:1#00", +"send packet: $OK#00", +"read packet: $c#00", +"send packet: $OK#00", +{"direction": "send", + "regex": self.fork_regex_nonstop.format(variant), + "capture": self.fork_capture}, +"read packet: $vStopped#00", +"send packet: $OK#00", +], True) +else: +self.test_sequence.add_log_lines([ +"read packet: $c#00", +{"direction": "send", "regex": self.fork_regex.format(variant), + "capture": self.fork_capture}, +], True) +ret = self.expect_gdbremote_sequence() +self.reset_test_sequence() + +return tuple(ret[x] for x in ("parent_pid", "parent_tid", + "child_pid", "child_tid")) + +def fork_and_detach_test(self, variant, nonstop=False): +parent_pid, parent_tid, child_pid, child_tid = ( +self.start_fork_test([variant], variant, nonstop=nonstop)) + +# detach the forked child +self.test_sequence.add_log_lines([ +"read packet: $D;{}#00".format(child_pid), +"send packet: $OK#00", +# verify that the current process is correct +"read packet: $qC#00", +"send packet: $QCp{}.{}#00".format(parent_pid, parent_tid), +# verify that the correct processes are detached/available +"read packet: $Hgp{}.{}#00".format(child_pid, child_tid), +"send packet: $Eff#00", +"read packet: $Hgp{}.{}#00".format(parent_pid, parent_tid), +"send packet: $OK#00", +], True) +self.expect_gdbremote_sequence() +self.reset_test_sequence() +return parent_pid, parent_tid + +def fork_and_follow_test(self, variant, nonstop=False): +parent_pid, parent_tid, child_pid, child_tid = ( +self.start_fork_test([variant], variant, nonstop=nonstop)) + +# switch to the forked child +self.test_sequence.add_log_lines([ +"read packet: $Hgp{}.{}#00".format(child_pid, child_tid), +"send packet: $OK#00", +"read packet: $Hcp{}.{}#00".format(child_pid, child_tid), +"send packet: $OK#00", +# detach the parent +"read packet: $D;{}#00".format(parent_pid), +"send packet: $OK#00", +# verify that the correct processes are detached/available +"read packet: $Hgp{}.{}#00".format(parent_pid, parent_tid), +"send packet: $Eff#00", +"read packet: $Hgp{}.{}#00".format(child_pid, child_tid), +"send packet: $OK#00",
[Lldb-commits] [lldb] 261d003 - [lldb] [llgs] Fix premature server exit if multiprocess+nonstop
Author: Michał Górny Date: 2022-06-28T21:49:17+02:00 New Revision: 261d0033500eaa281b74c9d54ae240257a0ea00c URL: https://github.com/llvm/llvm-project/commit/261d0033500eaa281b74c9d54ae240257a0ea00c DIFF: https://github.com/llvm/llvm-project/commit/261d0033500eaa281b74c9d54ae240257a0ea00c.diff LOG: [lldb] [llgs] Fix premature server exit if multiprocess+nonstop Fix lldb-server in the non-stop + multiprocess mode to exit on vStopped only if all processes have exited, rather than when the first one exits. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128639 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 49125f91d743a..63174ef552196 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -3860,9 +3860,9 @@ GDBRemoteCommunicationServerLLGS::Handle_vStopped( m_stop_notification_queue.pop_front(); if (!m_stop_notification_queue.empty()) return SendPacketNoLock(m_stop_notification_queue.front()); - // If this was the last notification and the process exited, terminate - // the server. - if (m_inferior_prev_state == eStateExited) { + // If this was the last notification and all the processes exited, + // terminate the server. + if (m_debugged_processes.empty()) { m_exit_now = true; m_mainloop.RequestTermination(); } diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 8b8e30c9b7379..c58f0fc381ebb 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -392,17 +392,17 @@ def test_vkill_both(self): def test_vkill_both_nonstop(self): self.vkill_test(kill_parent=True, kill_child=True, nonstop=True) -def resume_one_test(self, run_order, use_vCont=False): +def resume_one_test(self, run_order, use_vCont=False, nonstop=False): parent_pid, parent_tid, child_pid, child_tid = ( -self.start_fork_test(["fork", "trap"])) +self.start_fork_test(["fork", "trap"], nonstop=nonstop)) parent_expect = [ -"[$]T05thread:p{}.{};.*".format(parent_pid, parent_tid), -"[$]W00;process:{}#.*".format(parent_pid), +"T05thread:p{}.{};.*".format(parent_pid, parent_tid), +"W00;process:{}#.*".format(parent_pid), ] child_expect = [ -"[$]T05thread:p{}.{};.*".format(child_pid, child_tid), -"[$]W00;process:{}#.*".format(child_pid), +"T05thread:p{}.{};.*".format(child_pid, child_tid), +"W00;process:{}#.*".format(child_pid), ] for x in run_order: @@ -427,9 +427,17 @@ def resume_one_test(self, run_order, use_vCont=False): "send packet: $OK#00", "read packet: $c#00", ], True) -self.test_sequence.add_log_lines([ -{"direction": "send", "regex": expect}, -], True) +if nonstop: +self.test_sequence.add_log_lines([ +"send packet: $OK#00", +{"direction": "send", "regex": "%Stop:" + expect}, +"read packet: $vStopped#00", +"send packet: $OK#00", +], True) +else: +self.test_sequence.add_log_lines([ +{"direction": "send", "regex": "[$]" + expect}, +], True) # if at least one process remained, check both PIDs if parent_expect or child_expect: self.test_sequence.add_log_lines([ @@ -475,6 +483,14 @@ def test_c_child_then_parent(self): def test_c_interspersed(self): self.resume_one_test(run_order=["parent", "child", "parent", "child"]) +@expectedFailureAll(archs=["arm"]) # TODO +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) +@add_test_categories(["fork"]) +def test_c_interspersed_nonstop(self): +self.resume_one_test(run_order=["parent", "child", "parent", "child"], + nonstop=True) + @expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @@ -513,6 +529,14 @@ def test_vCont_interspersed(self): self.resume_one_test(run_order=["parent", "child",
[Lldb-commits] [lldb] e095cdd - [lldb] Add a NativeProcessProtocol::Threads() iterable
Author: Michał Górny Date: 2022-06-28T21:49:16+02:00 New Revision: e095cddb763fde72b577f3fab5e039cea4c3 URL: https://github.com/llvm/llvm-project/commit/e095cddb763fde72b577f3fab5e039cea4c3 DIFF: https://github.com/llvm/llvm-project/commit/e095cddb763fde72b577f3fab5e039cea4c3.diff LOG: [lldb] Add a NativeProcessProtocol::Threads() iterable Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128698 Added: Modified: lldb/include/lldb/Host/common/NativeProcessProtocol.h lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp Removed: diff --git a/lldb/include/lldb/Host/common/NativeProcessProtocol.h b/lldb/include/lldb/Host/common/NativeProcessProtocol.h index 63dbb3a62ea5f..37dacca6ff813 100644 --- a/lldb/include/lldb/Host/common/NativeProcessProtocol.h +++ b/lldb/include/lldb/Host/common/NativeProcessProtocol.h @@ -15,6 +15,7 @@ #include "lldb/Host/Host.h" #include "lldb/Host/MainLoop.h" #include "lldb/Utility/ArchSpec.h" +#include "lldb/Utility/Iterable.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/TraceGDBRemotePackets.h" #include "lldb/Utility/UnimplementedError.h" @@ -48,6 +49,16 @@ class NativeProcessProtocol { public: virtual ~NativeProcessProtocol() = default; + typedef std::vector> thread_collection; + template + static NativeThreadProtocol _list_adapter(I ) { +assert(*iter); +return **iter; + } + typedef LockingAdaptedIterable + ThreadIterable; + virtual Status Resume(const ResumeActionList _actions) = 0; virtual Status Halt() = 0; @@ -210,6 +221,10 @@ class NativeProcessProtocol { return GetThreadByID(m_current_thread_id); } + ThreadIterable Threads() const { +return ThreadIterable(m_threads, m_threads_mutex); + } + // Access to inferior stdio virtual int GetTerminalFileDescriptor() { return m_terminal_fd; } diff --git a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp index f7990f2d394fc..d038c78a59941 100644 --- a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp +++ b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp @@ -98,8 +98,8 @@ Error IntelPTCollector::TraceStart(const TraceIntelPTStartRequest ) { } } else { std::vector process_threads; - for (size_t i = 0; m_process.GetThreadAtIndex(i); i++) -process_threads.push_back(m_process.GetThreadAtIndex(i)->GetID()); + for (NativeThreadProtocol : m_process.Threads()) +process_threads.push_back(thread.GetID()); // per-thread process tracing if (Expected trace = diff --git a/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp b/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp index ef4c5ae46ed53..f538ef7776491 100644 --- a/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp +++ b/lldb/source/Plugins/Process/Linux/IntelPTMultiCoreTrace.cpp @@ -107,9 +107,9 @@ void IntelPTMultiCoreTrace::ProcessWillResume() { TraceIntelPTGetStateResponse IntelPTMultiCoreTrace::GetState() { TraceIntelPTGetStateResponse state; - for (size_t i = 0; m_process.GetThreadAtIndex(i); i++) + for (NativeThreadProtocol : m_process.Threads()) state.traced_threads.push_back( -TraceThreadState{m_process.GetThreadAtIndex(i)->GetID(), {}}); +TraceThreadState{thread.GetID(), {}}); state.cpus.emplace(); ForEachCore([&](lldb::cpu_id_t cpu_id, diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index ae8b8ef8ae156..49125f91d743a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -724,17 +724,12 @@ GetJSONThreadsInfo(NativeProcessProtocol , bool abridged) { json::Array threads_array; // Ensure we can get info on the given thread. - uint32_t thread_idx = 0; - for (NativeThreadProtocol *thread; - (thread = process.GetThreadAtIndex(thread_idx)) != nullptr; - ++thread_idx) { - -lldb::tid_t tid = thread->GetID(); - + for (NativeThreadProtocol : process.Threads()) { +lldb::tid_t tid = thread.GetID(); // Grab the reason this thread stopped. struct ThreadStopInfo tid_stop_info; std::string description; -if (!thread->GetStopReason(tid_stop_info, description)) +if (!thread.GetStopReason(tid_stop_info, description)) return llvm::make_error( "failed to get stop reason", llvm::inconvertibleErrorCode()); @@ -751,7 +746,7 @@ GetJSONThreadsInfo(NativeProcessProtocol , bool abridged) { json::Object
[Lldb-commits] [lldb] b415f8e - [lldb] [llgs] Add base nonstop fork/vfork tests
Author: Michał Górny Date: 2022-06-28T21:49:16+02:00 New Revision: b415f8e3dfb839a886b5290bbebbdd42344c07a9 URL: https://github.com/llvm/llvm-project/commit/b415f8e3dfb839a886b5290bbebbdd42344c07a9 DIFF: https://github.com/llvm/llvm-project/commit/b415f8e3dfb839a886b5290bbebbdd42344c07a9.diff LOG: [lldb] [llgs] Add base nonstop fork/vfork tests Extend the most of baseline fork tests to run in nonstop mode as well. For more cases, we're just testing one example scenario to save time. This patch does not cover tests that rely on correct exit handling, as fixing that is addressed in a followup patch. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128638 Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 70cea2f85f6ec..8b8e30c9b7379 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -9,10 +9,12 @@ class TestGdbRemoteFork(gdbremote_testcase.GdbRemoteTestCaseBase): fork_regex = ("[$]T05thread:p([0-9a-f]+)[.]([0-9a-f]+);.*" "{}:p([0-9a-f]+)[.]([0-9a-f]+).*") +fork_regex_nonstop = ("%Stop:T05thread:p([0-9a-f]+)[.]([0-9a-f]+);.*" + "{}:p([0-9a-f]+)[.]([0-9a-f]+).*") fork_capture = {1: "parent_pid", 2: "parent_tid", 3: "child_pid", 4: "child_tid"} -def start_fork_test(self, args, variant="fork"): +def start_fork_test(self, args, variant="fork", nonstop=False): self.build() self.prep_debug_monitor_and_inferior(inferior_args=args) self.add_qSupported_packets(["multiprocess+", @@ -22,11 +24,24 @@ def start_fork_test(self, args, variant="fork"): self.reset_test_sequence() # continue and expect fork -self.test_sequence.add_log_lines([ -"read packet: $c#00", -{"direction": "send", "regex": self.fork_regex.format(variant), - "capture": self.fork_capture}, -], True) +if nonstop: +self.test_sequence.add_log_lines([ +"read packet: $QNonStop:1#00", +"send packet: $OK#00", +"read packet: $c#00", +"send packet: $OK#00", +{"direction": "send", + "regex": self.fork_regex_nonstop.format(variant), + "capture": self.fork_capture}, +"read packet: $vStopped#00", +"send packet: $OK#00", +], True) +else: +self.test_sequence.add_log_lines([ +"read packet: $c#00", +{"direction": "send", "regex": self.fork_regex.format(variant), + "capture": self.fork_capture}, +], True) ret = self.expect_gdbremote_sequence() self.reset_test_sequence() @@ -45,9 +60,9 @@ def test_fork_multithreaded(self): ], True) self.expect_gdbremote_sequence() -def fork_and_detach_test(self, variant): +def fork_and_detach_test(self, variant, nonstop=False): parent_pid, parent_tid, child_pid, child_tid = ( -self.start_fork_test([variant], variant)) +self.start_fork_test([variant], variant, nonstop=nonstop)) # detach the forked child self.test_sequence.add_log_lines([ @@ -77,6 +92,20 @@ def test_fork(self): ], True) self.expect_gdbremote_sequence() +@add_test_categories(["fork"]) +def test_fork_nonstop(self): +parent_pid, _ = self.fork_and_detach_test("fork", nonstop=True) + +# resume the parent +self.test_sequence.add_log_lines([ +"read packet: $c#00", +"send packet: $OK#00", +"send packet: %Stop:W00;process:{}#00".format(parent_pid), +"read packet: $vStopped#00", +"send packet: $OK#00", +], True) +self.expect_gdbremote_sequence() + @add_test_categories(["fork"]) def test_vfork(self): parent_pid, parent_tid = self.fork_and_detach_test("vfork") @@ -93,9 +122,32 @@ def test_vfork(self): ], True) self.expect_gdbremote_sequence() -def fork_and_follow_test(self, variant): +@add_test_categories(["fork"]) +def test_vfork_nonstop(self): +parent_pid, parent_tid = self.fork_and_detach_test("vfork", + nonstop=True) + +# resume the parent +self.test_sequence.add_log_lines([ +"read packet: $c#00", +"send packet: $OK#00", +{"direction": "send", + "regex": r"%Stop:T05thread:p{}[.]{}.*vforkdone.*".format( + parent_pid, parent_tid), + }, +
[Lldb-commits] [lldb] 25f4608 - [lldb] [test] XFAIL llgs tests failing on arm
Author: Michał Górny Date: 2022-06-28T17:02:59+02:00 New Revision: 25f46084d8e11894edc0b71b737f45e0f9115b45 URL: https://github.com/llvm/llvm-project/commit/25f46084d8e11894edc0b71b737f45e0f9115b45 DIFF: https://github.com/llvm/llvm-project/commit/25f46084d8e11894edc0b71b737f45e0f9115b45.diff LOG: [lldb] [test] XFAIL llgs tests failing on arm Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index aa97ccd51458..70cea2f85f6e 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -317,48 +317,56 @@ def resume_one_test(self, run_order, use_vCont=False): ], True) self.expect_gdbremote_sequence() +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_parent(self): self.resume_one_test(run_order=["parent", "parent"]) +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_child(self): self.resume_one_test(run_order=["child", "child"]) +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_parent_then_child(self): self.resume_one_test(run_order=["parent", "parent", "child", "child"]) +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_child_then_parent(self): self.resume_one_test(run_order=["child", "child", "parent", "parent"]) +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_interspersed(self): self.resume_one_test(run_order=["parent", "child", "parent", "child"]) +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_vCont_parent(self): self.resume_one_test(run_order=["parent", "parent"], use_vCont=True) +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_vCont_child(self): self.resume_one_test(run_order=["child", "child"], use_vCont=True) +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) @@ -366,6 +374,7 @@ def test_vCont_parent_then_child(self): self.resume_one_test(run_order=["parent", "parent", "child", "child"], use_vCont=True) +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) @@ -373,6 +382,7 @@ def test_vCont_child_then_parent(self): self.resume_one_test(run_order=["child", "child", "parent", "parent"], use_vCont=True) +@expectedFailureAll(archs=["arm"]) # TODO @expectedFailureAll(archs=["aarch64"], bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) @@ -415,6 +425,7 @@ def test_vCont_all_processes_implicit(self): ], True) self.expect_gdbremote_sequence() +@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_threadinfo(self): parent_pid, parent_tid, child_pid, child_tid = ( @@ -460,6 +471,7 @@ def test_threadinfo(self): ], True) self.expect_gdbremote_sequence() +@expectedFailureAll(archs=["arm"]) # TODO @add_test_categories(["fork"]) def test_memory_read_write(self): self.build() @@ -547,6 +559,7 @@ def test_memory_read_write(self): self.assertEqual(data, name + "\0")
[Lldb-commits] [lldb] a1df636 - [lldb] [test] Skip llgs tests broken due to #56268 on aarch64
Author: Michał Górny Date: 2022-06-28T16:24:38+02:00 New Revision: a1df636a8b51a660d58708d82a5bc060ee5f57d3 URL: https://github.com/llvm/llvm-project/commit/a1df636a8b51a660d58708d82a5bc060ee5f57d3 DIFF: https://github.com/llvm/llvm-project/commit/a1df636a8b51a660d58708d82a5bc060ee5f57d3.diff LOG: [lldb] [test] Skip llgs tests broken due to #56268 on aarch64 Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index d8c93b84d0ce5..aa97ccd514583 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -317,44 +317,64 @@ def resume_one_test(self, run_order, use_vCont=False): ], True) self.expect_gdbremote_sequence() +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_parent(self): self.resume_one_test(run_order=["parent", "parent"]) +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_child(self): self.resume_one_test(run_order=["child", "child"]) +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_parent_then_child(self): self.resume_one_test(run_order=["parent", "parent", "child", "child"]) +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_child_then_parent(self): self.resume_one_test(run_order=["child", "child", "parent", "parent"]) +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_c_interspersed(self): self.resume_one_test(run_order=["parent", "child", "parent", "child"]) +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_vCont_parent(self): self.resume_one_test(run_order=["parent", "parent"], use_vCont=True) +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_vCont_child(self): self.resume_one_test(run_order=["child", "child"], use_vCont=True) +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_vCont_parent_then_child(self): self.resume_one_test(run_order=["parent", "parent", "child", "child"], use_vCont=True) +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_vCont_child_then_parent(self): self.resume_one_test(run_order=["child", "child", "parent", "parent"], use_vCont=True) +@expectedFailureAll(archs=["aarch64"], + bugnumber="https://github.com/llvm/llvm-project/issues/56268;) @add_test_categories(["fork"]) def test_vCont_interspersed(self): self.resume_one_test(run_order=["parent", "child", "parent", "child"], ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] f1dcc6a - [lldb] [test] Mark test_vCont_supports_t llgs-only
Author: Michał Górny Date: 2022-06-28T06:06:54+02:00 New Revision: f1dcc6af30d98cef6d0aa9579148fa223dbb5d7c URL: https://github.com/llvm/llvm-project/commit/f1dcc6af30d98cef6d0aa9579148fa223dbb5d7c DIFF: https://github.com/llvm/llvm-project/commit/f1dcc6af30d98cef6d0aa9579148fa223dbb5d7c.diff LOG: [lldb] [test] Mark test_vCont_supports_t llgs-only Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py b/lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py index c17d0b7740dde..7b20ef230ba94 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py @@ -39,6 +39,7 @@ def test_vCont_supports_S(self): self.build() self.vCont_supports_mode("S") +@add_test_categories(["llgs"]) def test_vCont_supports_t(self): self.build() self.vCont_supports_mode("t") ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] fe80829 - [lldb] [llgs] Skip new vCont test on Windows
Author: Michał Górny Date: 2022-06-27T18:22:38+02:00 New Revision: fe80829289bf5462bff5d6739603e7040d07a391 URL: https://github.com/llvm/llvm-project/commit/fe80829289bf5462bff5d6739603e7040d07a391 DIFF: https://github.com/llvm/llvm-project/commit/fe80829289bf5462bff5d6739603e7040d07a391.diff LOG: [lldb] [llgs] Skip new vCont test on Windows Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py Removed: diff --git a/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py b/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py index 2a3275004e83..fd3deecd2fab 100644 --- a/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py +++ b/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py @@ -261,6 +261,7 @@ def continue_and_get_threads_running(self, continue_packet): found.add(int(m.group(1), 16)) return found +@skipIfWindows @add_test_categories(["llgs"]) def test_vCont_run_subset_of_threads(self): self.build() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] b4f2d7c - [lldb] [llgs] Support "t" vCont action
Author: Michał Górny Date: 2022-06-27T17:33:59+02:00 New Revision: b4f2d7cde54c301f591a8e2a16135bb113c5e7ed URL: https://github.com/llvm/llvm-project/commit/b4f2d7cde54c301f591a8e2a16135bb113c5e7ed DIFF: https://github.com/llvm/llvm-project/commit/b4f2d7cde54c301f591a8e2a16135bb113c5e7ed.diff LOG: [lldb] [llgs] Support "t" vCont action Implement support for the "t" action that is used to stop a thread. Normally this action is used only in non-stop mode. However, there's no technical reason why it couldn't be also used in all-stop mode, e.g. to express "resume all threads except ..." (`t:...;c`). While at it, add a more complete test for vCont correctly resuming a subset of program's threads. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D126983 Added: Modified: lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py lldb/test/API/tools/lldb-server/vCont-threads/main.cpp Removed: diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index 5324a2c0bf51e..0fb4c691118b7 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -947,7 +947,7 @@ Status NativeProcessLinux::Resume(const ResumeActionList _actions) { case eStateSuspended: case eStateStopped: - llvm_unreachable("Unexpected state"); + break; default: return Status("NativeProcessLinux::%s (): unexpected state %s specified " diff --git a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp index 10647839eec2e..a6d7500f41792 100644 --- a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp +++ b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp @@ -117,7 +117,7 @@ Status NativeProcessWindows::Resume(const ResumeActionList _actions) { } case eStateSuspended: case eStateStopped: -llvm_unreachable("Unexpected state"); +break; default: return Status( diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 2c009ef7fcd9a..ae8b8ef8ae156 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1654,7 +1654,7 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_vCont_actions( StringExtractorGDBRemote ) { StreamString response; - response.Printf("vCont;c;C;s;S"); + response.Printf("vCont;c;C;s;S;t"); return SendPacketNoLock(response.GetString()); } @@ -1723,6 +1723,11 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont( thread_action.state = eStateStepping; break; +case 't': + // Stop + thread_action.state = eStateSuspended; + break; + default: return SendIllFormedResponse(packet, "Unsupported vCont action"); break; diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py b/lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py index db1e39b9759d7..c17d0b7740dde 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemote_vCont.py @@ -39,6 +39,10 @@ def test_vCont_supports_S(self): self.build() self.vCont_supports_mode("S") +def test_vCont_supports_t(self): +self.build() +self.vCont_supports_mode("t") + @skipIfWindows # No pty support to test O* & I* notification packets. @skipIf(triple='^mips') def test_single_step_only_steps_one_instruction_with_Hc_vCont_s(self): diff --git a/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py b/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py index 30a136f127787..2a3275004e831 100644 --- a/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py +++ b/lldb/test/API/tools/lldb-server/vCont-threads/TestGdbRemote_vContThreads.py @@ -1,5 +1,6 @@ import json import re +import time import gdbremote_testcase from lldbsuite.test.decorators import * @@ -13,8 +14,7 @@ def start_threads(self, num): # start the process and wait for output self.test_sequence.add_log_lines([ "read packet: $c#63", -{"type": "output_match", "regex":
[Lldb-commits] [lldb] 1452e2e - Reland "[lldb] [llgs] Support multiprocess in qfThreadInfo"
Author: Michał Górny Date: 2022-06-25T15:15:37+02:00 New Revision: 1452e2e5cbfe69cd6622a3c9e80dd485f1fb542b URL: https://github.com/llvm/llvm-project/commit/1452e2e5cbfe69cd6622a3c9e80dd485f1fb542b DIFF: https://github.com/llvm/llvm-project/commit/1452e2e5cbfe69cd6622a3c9e80dd485f1fb542b.diff LOG: Reland "[lldb] [llgs] Support multiprocess in qfThreadInfo" Now preserving the non-standard behavior of returning "OK" response when there is no debugged process. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128152 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 770edbfec2807..2c009ef7fcd9a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1976,38 +1976,43 @@ GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo( return SendPacketNoLock(response.GetString()); } -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo( -StringExtractorGDBRemote ) { +void GDBRemoteCommunicationServerLLGS::AddProcessThreads( +StreamGDBRemote , NativeProcessProtocol , bool _any) { Log *log = GetLog(LLDBLog::Thread); - // Fail if we don't have a current process. - if (!m_current_process || - (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { -LLDB_LOG(log, "no process ({0}), returning OK", - m_current_process ? "invalid process id" - : "null m_current_process"); -return SendOKResponse(); - } - - StreamGDBRemote response; - response.PutChar('m'); + lldb::pid_t pid = process.GetID(); + if (pid == LLDB_INVALID_PROCESS_ID) +return; - LLDB_LOG(log, "starting thread iteration"); + LLDB_LOG(log, "iterating over threads of process {0}", process.GetID()); NativeThreadProtocol *thread; uint32_t thread_index; - for (thread_index = 0, - thread = m_current_process->GetThreadAtIndex(thread_index); - thread; ++thread_index, - thread = m_current_process->GetThreadAtIndex(thread_index)) { -LLDB_LOG(log, "iterated thread {0}(tid={2})", thread_index, + for (thread_index = 0, thread = process.GetThreadAtIndex(thread_index); + thread; + ++thread_index, thread = process.GetThreadAtIndex(thread_index)) { +LLDB_LOG(log, "iterated thread {0} (tid={1})", thread_index, thread->GetID()); -if (thread_index > 0) - response.PutChar(','); -response.Printf("%" PRIx64, thread->GetID()); +response.PutChar(had_any ? ',' : 'm'); +AppendThreadIDToResponse(response, pid, thread->GetID()); +had_any = true; } +} - LLDB_LOG(log, "finished thread iteration"); +GDBRemoteCommunication::PacketResult +GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo( +StringExtractorGDBRemote ) { + assert(m_debugged_processes.size() == 1 || + bool(m_extensions_supported & + NativeProcessProtocol::Extension::multiprocess)); + + bool had_any = false; + StreamGDBRemote response; + + for (auto _ptr : m_debugged_processes) +AddProcessThreads(response, *pid_ptr.second, had_any); + + if (!had_any) +return SendOKResponse(); return SendPacketNoLock(response.GetString()); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h index 17cc321c39676..5187a953f957e 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -159,6 +159,9 @@ class GDBRemoteCommunicationServerLLGS PacketResult Handle_qRegisterInfo(StringExtractorGDBRemote ); + void AddProcessThreads(StreamGDBRemote , + NativeProcessProtocol , bool _any); + PacketResult Handle_qfThreadInfo(StringExtractorGDBRemote ); PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote ); diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index b60481a9d1687..d8c93b84d0ce5 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -396,7 +396,6 @@ def test_vCont_all_processes_implicit(self): self.expect_gdbremote_sequence() @add_test_categories(["fork"]) -@expectedFailureAll() # qfThreadInfo changes temporarily reverted def
[Lldb-commits] [lldb] f609b54 - Revert "[lldb] [llgs] Support multiprocess in qfThreadInfo"
Author: Michał Górny Date: 2022-06-25T09:46:28+02:00 New Revision: f609b54e249a4eb9b5f68a26b3fecba87d7324c0 URL: https://github.com/llvm/llvm-project/commit/f609b54e249a4eb9b5f68a26b3fecba87d7324c0 DIFF: https://github.com/llvm/llvm-project/commit/f609b54e249a4eb9b5f68a26b3fecba87d7324c0.diff LOG: Revert "[lldb] [llgs] Support multiprocess in qfThreadInfo" This reverts part of commit 75757c86c695a6b4695458343637b3c4fe86def6. It broke the following test: commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py I need more time to figure it out, so I'm reverting the code changes and marking the tests depending on them xfail. Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 9356b01a6ce8f..770edbfec2807 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1976,43 +1976,38 @@ GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo( return SendPacketNoLock(response.GetString()); } -void GDBRemoteCommunicationServerLLGS::AddProcessThreads( -StreamGDBRemote , NativeProcessProtocol , bool _any) { +GDBRemoteCommunication::PacketResult +GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo( +StringExtractorGDBRemote ) { Log *log = GetLog(LLDBLog::Thread); - lldb::pid_t pid = process.GetID(); - if (pid == LLDB_INVALID_PROCESS_ID) -return; + // Fail if we don't have a current process. + if (!m_current_process || + (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { +LLDB_LOG(log, "no process ({0}), returning OK", + m_current_process ? "invalid process id" + : "null m_current_process"); +return SendOKResponse(); + } - LLDB_LOG(log, "iterating over threads of process {0}", process.GetID()); + StreamGDBRemote response; + response.PutChar('m'); + + LLDB_LOG(log, "starting thread iteration"); NativeThreadProtocol *thread; uint32_t thread_index; - for (thread_index = 0, thread = process.GetThreadAtIndex(thread_index); - thread; - ++thread_index, thread = process.GetThreadAtIndex(thread_index)) { -LLDB_LOG(log, "iterated thread {0} (tid={1})", thread_index, + for (thread_index = 0, + thread = m_current_process->GetThreadAtIndex(thread_index); + thread; ++thread_index, + thread = m_current_process->GetThreadAtIndex(thread_index)) { +LLDB_LOG(log, "iterated thread {0}(tid={2})", thread_index, thread->GetID()); -response.PutChar(had_any ? ',' : 'm'); -AppendThreadIDToResponse(response, pid, thread->GetID()); -had_any = true; +if (thread_index > 0) + response.PutChar(','); +response.Printf("%" PRIx64, thread->GetID()); } -} -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo( -StringExtractorGDBRemote ) { - assert(m_debugged_processes.size() == 1 || - bool(m_extensions_supported & - NativeProcessProtocol::Extension::multiprocess)); - - bool had_any = false; - StreamGDBRemote response; - - for (auto _ptr : m_debugged_processes) -AddProcessThreads(response, *pid_ptr.second, had_any); - - if (!had_any) -response.PutChar('l'); + LLDB_LOG(log, "finished thread iteration"); return SendPacketNoLock(response.GetString()); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h index 5187a953f957e..17cc321c39676 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -159,9 +159,6 @@ class GDBRemoteCommunicationServerLLGS PacketResult Handle_qRegisterInfo(StringExtractorGDBRemote ); - void AddProcessThreads(StreamGDBRemote , - NativeProcessProtocol , bool _any); - PacketResult Handle_qfThreadInfo(StringExtractorGDBRemote ); PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote ); diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index d8c93b84d0ce5..b60481a9d1687 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -396,6 +396,7 @@ def test_vCont_all_processes_implicit(self): self.expect_gdbremote_sequence()
[Lldb-commits] [lldb] c1829e0 - [lldb] [test] Move part of fork tests to common helper
Author: Michał Górny Date: 2022-06-24T17:20:25+02:00 New Revision: c1829e0ec58bd974e65639de0b9cbab736bb624f URL: https://github.com/llvm/llvm-project/commit/c1829e0ec58bd974e65639de0b9cbab736bb624f DIFF: https://github.com/llvm/llvm-project/commit/c1829e0ec58bd974e65639de0b9cbab736bb624f.diff LOG: [lldb] [test] Move part of fork tests to common helper Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128361 Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 23e387afd4cd..d8c93b84d0ce 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -12,25 +12,31 @@ class TestGdbRemoteFork(gdbremote_testcase.GdbRemoteTestCaseBase): fork_capture = {1: "parent_pid", 2: "parent_tid", 3: "child_pid", 4: "child_tid"} -@add_test_categories(["fork"]) -def test_fork_multithreaded(self): +def start_fork_test(self, args, variant="fork"): self.build() -self.prep_debug_monitor_and_inferior(inferior_args=["thread:new"]*2 + ["fork"]) -self.add_qSupported_packets(["multiprocess+", "fork-events+"]) +self.prep_debug_monitor_and_inferior(inferior_args=args) +self.add_qSupported_packets(["multiprocess+", + "{}-events+".format(variant)]) ret = self.expect_gdbremote_sequence() -self.assertIn("fork-events+", ret["qSupported_response"]) +self.assertIn("{}-events+".format(variant), ret["qSupported_response"]) self.reset_test_sequence() # continue and expect fork self.test_sequence.add_log_lines([ "read packet: $c#00", -{"direction": "send", "regex": self.fork_regex.format("fork"), +{"direction": "send", "regex": self.fork_regex.format(variant), "capture": self.fork_capture}, ], True) ret = self.expect_gdbremote_sequence() -child_pid = ret["child_pid"] self.reset_test_sequence() +return tuple(ret[x] for x in ("parent_pid", "parent_tid", + "child_pid", "child_tid")) + +@add_test_categories(["fork"]) +def test_fork_multithreaded(self): +_, _, child_pid, _ = self.start_fork_test(["thread:new"]*2 + ["fork"]) + # detach the forked child self.test_sequence.add_log_lines([ "read packet: $D;{}#00".format(child_pid), @@ -40,26 +46,8 @@ def test_fork_multithreaded(self): self.expect_gdbremote_sequence() def fork_and_detach_test(self, variant): -self.build() -self.prep_debug_monitor_and_inferior(inferior_args=[variant]) -self.add_qSupported_packets(["multiprocess+", - "{}-events+".format(variant)]) -ret = self.expect_gdbremote_sequence() -self.assertIn("{}-events+".format(variant), ret["qSupported_response"]) -self.reset_test_sequence() - -# continue and expect fork -self.test_sequence.add_log_lines([ -"read packet: $c#00", -{"direction": "send", "regex": self.fork_regex.format(variant), - "capture": self.fork_capture}, -], True) -ret = self.expect_gdbremote_sequence() -parent_pid = ret["parent_pid"] -parent_tid = ret["parent_tid"] -child_pid = ret["child_pid"] -child_tid = ret["child_tid"] -self.reset_test_sequence() +parent_pid, parent_tid, child_pid, child_tid = ( +self.start_fork_test([variant], variant)) # detach the forked child self.test_sequence.add_log_lines([ @@ -106,26 +94,8 @@ def test_vfork(self): self.expect_gdbremote_sequence() def fork_and_follow_test(self, variant): -self.build() -self.prep_debug_monitor_and_inferior(inferior_args=[variant]) -self.add_qSupported_packets(["multiprocess+", - "{}-events+".format(variant)]) -ret = self.expect_gdbremote_sequence() -self.assertIn("{}-events+".format(variant), ret["qSupported_response"]) -self.reset_test_sequence() - -# continue and expect fork -self.test_sequence.add_log_lines([ -"read packet: $c#00", -{"direction": "send", "regex": self.fork_regex.format(variant), - "capture": self.fork_capture}, -], True) -ret = self.expect_gdbremote_sequence() -parent_pid = ret["parent_pid"] -parent_tid = ret["parent_tid"] -child_pid = ret["child_pid"] -child_tid = ret["child_tid"] -self.reset_test_sequence() +parent_pid, parent_tid,
[Lldb-commits] [lldb] 4b485fc - [lldb] [llgs] Introduce an AppendThreadIDToResponse() helper
Author: Michał Górny Date: 2022-06-24T17:20:24+02:00 New Revision: 4b485fc0ea4acf065c7992a5c9a1223f5565544e URL: https://github.com/llvm/llvm-project/commit/4b485fc0ea4acf065c7992a5c9a1223f5565544e DIFF: https://github.com/llvm/llvm-project/commit/4b485fc0ea4acf065c7992a5c9a1223f5565544e.diff LOG: [lldb] [llgs] Introduce an AppendThreadIDToResponse() helper Introduce a helper function to append GDB Remote Serial Protocol "thread IDs", with optional PID in multiprocess mode. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128324 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index f5c66496d765..9356b01a6ce8 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -826,10 +826,8 @@ GDBRemoteCommunicationServerLLGS::PrepareStopReplyPacketForThread( // Include the (pid and) tid. response.PutCString("thread:"); - if (bool(m_extensions_supported & - NativeProcessProtocol::Extension::multiprocess)) -response.Format("p{0:x-}.", process.GetID()); - response.Format("{0:x-};", thread.GetID()); + AppendThreadIDToResponse(response, process.GetID(), thread.GetID()); + response.PutChar(';'); // Include the thread name if there is one. const std::string thread_name = thread.GetName(); @@ -1425,9 +1423,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qC(StringExtractorGDBRemote ) { StreamString response; response.PutCString("QC"); - if (bool(m_extensions_supported & NativeProcessProtocol::Extension::multiprocess)) -response.Format("p{0:x-}.", m_current_process->GetID()); - response.Format("{0:x-}", thread->GetID()); + AppendThreadIDToResponse(response, m_current_process->GetID(), + thread->GetID()); return SendPacketNoLock(response.GetString()); } @@ -1996,10 +1993,7 @@ void GDBRemoteCommunicationServerLLGS::AddProcessThreads( LLDB_LOG(log, "iterated thread {0} (tid={1})", thread_index, thread->GetID()); response.PutChar(had_any ? ',' : 'm'); -if (bool(m_extensions_supported & - NativeProcessProtocol::Extension::multiprocess)) - response.Format("p{0:x-}.", pid); -response.Format("{0:x-}", thread->GetID()); +AppendThreadIDToResponse(response, pid, thread->GetID()); had_any = true; } } @@ -4143,6 +4137,14 @@ GDBRemoteCommunicationServerLLGS::SendContinueSuccessResponse() { return m_non_stop ? SendOKResponse() : PacketResult::Success; } +void GDBRemoteCommunicationServerLLGS::AppendThreadIDToResponse( +Stream , lldb::pid_t pid, lldb::tid_t tid) { + if (bool(m_extensions_supported & + NativeProcessProtocol::Extension::multiprocess)) +response.Format("p{0:x-}.", pid); + response.Format("{0:x-}", tid); +} + std::string lldb_private::process_gdb_remote::LLGSArgToURL(llvm::StringRef url_arg, bool reverse_connect) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h index abb7f10f4830..5187a953f957 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -273,6 +273,9 @@ class GDBRemoteCommunicationServerLLGS // in non-stop mode, no response otherwise. PacketResult SendContinueSuccessResponse(); + void AppendThreadIDToResponse(Stream , lldb::pid_t pid, +lldb::tid_t tid); + private: llvm::Expected> BuildTargetXml(); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] e827e51 - [lldb] [llgs] Implement the 'T' packet
Author: Michał Górny Date: 2022-06-24T17:20:24+02:00 New Revision: e827e5186fb6991bc749eaaddf13f8a53ebb63c2 URL: https://github.com/llvm/llvm-project/commit/e827e5186fb6991bc749eaaddf13f8a53ebb63c2 DIFF: https://github.com/llvm/llvm-project/commit/e827e5186fb6991bc749eaaddf13f8a53ebb63c2.diff LOG: [lldb] [llgs] Implement the 'T' packet Implement the 'T' packet that is used to verify whether the specified thread belongs to the debugged processes. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128170 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 18712cf5b323b..f5c66496d7659 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -107,6 +107,8 @@ void GDBRemoteCommunicationServerLLGS::RegisterPacketHandlers() { ::Handle_P); RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qC, ::Handle_qC); + RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_T, +::Handle_T); RegisterMemberFunctionHandler( StringExtractorGDBRemote::eServerPacketType_qfThreadInfo, ::Handle_qfThreadInfo); @@ -3898,6 +3900,36 @@ GDBRemoteCommunicationServerLLGS::Handle_vCtrlC( return SendOKResponse(); } +GDBRemoteCommunication::PacketResult +GDBRemoteCommunicationServerLLGS::Handle_T(StringExtractorGDBRemote ) { + packet.SetFilePos(strlen("T")); + auto pid_tid = packet.GetPidTid(m_current_process ? m_current_process->GetID() +: LLDB_INVALID_PROCESS_ID); + if (!pid_tid) +return SendErrorResponse(llvm::make_error( +inconvertibleErrorCode(), "Malformed thread-id")); + + lldb::pid_t pid = pid_tid->first; + lldb::tid_t tid = pid_tid->second; + + // Technically, this would also be caught by the PID check but let's be more + // explicit about the error. + if (pid == LLDB_INVALID_PROCESS_ID) +return SendErrorResponse(llvm::make_error( +inconvertibleErrorCode(), "No current process and no PID provided")); + + // Check the process ID and find respective process instance. + auto new_process_it = m_debugged_processes.find(pid); + if (new_process_it == m_debugged_processes.end()) +return SendErrorResponse(1); + + // Check the thread ID + if (!new_process_it->second->GetThreadByID(tid)) +return SendErrorResponse(2); + + return SendOKResponse(); +} + void GDBRemoteCommunicationServerLLGS::MaybeCloseInferiorTerminalConnection() { Log *log = GetLog(LLDBLog::Process); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h index 03a548b076e46..abb7f10f4830f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -246,6 +246,8 @@ class GDBRemoteCommunicationServerLLGS PacketResult Handle_QMemTags(StringExtractorGDBRemote ); + PacketResult Handle_T(StringExtractorGDBRemote ); + void SetCurrentThreadID(lldb::tid_t tid); lldb::tid_t GetCurrentThreadID() const; diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index fdd9e94d0a364..23e387afd4cd4 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -866,3 +866,76 @@ def test_qC(self): "send packet: $QCp{:x}.{:x}#00".format(*pidtid), ], True) self.expect_gdbremote_sequence() + +@add_test_categories(["fork"]) +def test_T(self): +self.build() +self.prep_debug_monitor_and_inferior( +inferior_args=["fork", + "thread:new", + "trap", + ]) +self.add_qSupported_packets(["multiprocess+", + "fork-events+"]) +ret = self.expect_gdbremote_sequence() +self.assertIn("fork-events+", ret["qSupported_response"]) +self.reset_test_sequence() + +# continue and expect fork +self.test_sequence.add_log_lines([ +"read packet: $c#00", +{"direction": "send", "regex": self.fork_regex.format("fork"), +
[Lldb-commits] [lldb] 630da0e - [lldb] [llgs] Include PID in QC response in multiprocess mode
Author: Michał Górny Date: 2022-06-24T17:20:24+02:00 New Revision: 630da0e309ef4764465dcaf559676633e948f5c0 URL: https://github.com/llvm/llvm-project/commit/630da0e309ef4764465dcaf559676633e948f5c0 DIFF: https://github.com/llvm/llvm-project/commit/630da0e309ef4764465dcaf559676633e948f5c0.diff LOG: [lldb] [llgs] Include PID in QC response in multiprocess mode Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128156 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 8c26032cc90db..18712cf5b323b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1422,7 +1422,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qC(StringExtractorGDBRemote ) { return SendErrorResponse(69); StreamString response; - response.Printf("QC%" PRIx64, thread->GetID()); + response.PutCString("QC"); + if (bool(m_extensions_supported & NativeProcessProtocol::Extension::multiprocess)) +response.Format("p{0:x-}.", m_current_process->GetID()); + response.Format("{0:x-}", thread->GetID()); return SendPacketNoLock(response.GetString()); } diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 78e7d24f0db93..fdd9e94d0a364 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -11,7 +11,6 @@ class TestGdbRemoteFork(gdbremote_testcase.GdbRemoteTestCaseBase): "{}:p([0-9a-f]+)[.]([0-9a-f]+).*") fork_capture = {1: "parent_pid", 2: "parent_tid", 3: "child_pid", 4: "child_tid"} -procinfo_regex = "[$]pid:([0-9a-f]+);.*" @add_test_categories(["fork"]) def test_fork_multithreaded(self): @@ -68,7 +67,7 @@ def fork_and_detach_test(self, variant): "send packet: $OK#00", # verify that the current process is correct "read packet: $qC#00", -"send packet: $QC{}#00".format(parent_tid), +"send packet: $QCp{}.{}#00".format(parent_pid, parent_tid), # verify that the correct processes are detached/available "read packet: $Hgp{}.{}#00".format(child_pid, child_tid), "send packet: $Eff#00", @@ -167,12 +166,9 @@ def test_select_wrong_pid(self): # get process pid self.test_sequence.add_log_lines([ -"read packet: $qProcessInfo#00", -{"direction": "send", "regex": self.procinfo_regex, - "capture": {1: "pid"}}, "read packet: $qC#00", -{"direction": "send", "regex": "[$]QC([0-9a-f]+)#.*", - "capture": {1: "tid"}}, +{"direction": "send", "regex": "[$]QCp([0-9a-f]+).([0-9a-f]+)#.*", + "capture": {1: "pid", 2: "tid"}}, ], True) ret = self.expect_gdbremote_sequence() pid, tid = (int(ret[x], 16) for x in ("pid", "tid")) @@ -208,8 +204,8 @@ def test_detach_current(self): # get process pid self.test_sequence.add_log_lines([ -"read packet: $qProcessInfo#00", -{"direction": "send", "regex": self.procinfo_regex, +"read packet: $qC#00", +{"direction": "send", "regex": "[$]QCp([0-9a-f]+).[0-9a-f]+#.*", "capture": {1: "pid"}}, ], True) ret = self.expect_gdbremote_sequence() @@ -817,3 +813,56 @@ def test_register_read_write(self): data = ret.get("data") self.assertIsNotNone(data) self.assertEqual(data, old_val[1]) + +@add_test_categories(["fork"]) +def test_qC(self): +self.build() +self.prep_debug_monitor_and_inferior( +inferior_args=["fork", + "thread:new", + "trap", + ]) +self.add_qSupported_packets(["multiprocess+", + "fork-events+"]) +ret = self.expect_gdbremote_sequence() +self.assertIn("fork-events+", ret["qSupported_response"]) +self.reset_test_sequence() + +# continue and expect fork +self.test_sequence.add_log_lines([ +"read packet: $c#00", +{"direction": "send", "regex": self.fork_regex.format("fork"), + "capture": self.fork_capture}, +], True) +self.add_threadinfo_collection_packets() +ret = self.expect_gdbremote_sequence() +pidtids = [ +(ret["parent_pid"],
[Lldb-commits] [lldb] 14d6707 - [lldb] [llgs] Add a test for multiprocess register read/write
Author: Michał Górny Date: 2022-06-24T17:20:24+02:00 New Revision: 14d67073359a86f1d2ae9e140f0b29aa4e63a3af URL: https://github.com/llvm/llvm-project/commit/14d67073359a86f1d2ae9e140f0b29aa4e63a3af DIFF: https://github.com/llvm/llvm-project/commit/14d67073359a86f1d2ae9e140f0b29aa4e63a3af.diff LOG: [lldb] [llgs] Add a test for multiprocess register read/write Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128153 Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 31f8a1336b58f..78e7d24f0db93 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -1,3 +1,5 @@ +import random + import gdbremote_testcase from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -700,3 +702,118 @@ def test_memory_read_write(self): data = seven.unhexlify(ret.get("data")) self.assertEqual(data, name + "\0") self.reset_test_sequence() + +@add_test_categories(["fork"]) +def test_register_read_write(self): +self.build() +self.prep_debug_monitor_and_inferior( +inferior_args=["fork", + "thread:new", + "trap", + ]) +self.add_qSupported_packets(["multiprocess+", + "fork-events+"]) +ret = self.expect_gdbremote_sequence() +self.assertIn("fork-events+", ret["qSupported_response"]) +self.reset_test_sequence() + +# continue and expect fork +self.test_sequence.add_log_lines([ +"read packet: $c#00", +{"direction": "send", "regex": self.fork_regex.format("fork"), + "capture": self.fork_capture}, +], True) +self.add_threadinfo_collection_packets() +ret = self.expect_gdbremote_sequence() +pidtids = [ +(ret["parent_pid"], ret["parent_tid"]), +(ret["child_pid"], ret["child_tid"]), +] +self.reset_test_sequence() + +for pidtid in pidtids: +self.test_sequence.add_log_lines( +["read packet: $Hcp{}.{}#00".format(*pidtid), + "send packet: $OK#00", + "read packet: $c#00", + {"direction": "send", + "regex": "^[$]T05thread:p{}.{}.*".format(*pidtid), + }, + ], True) + +self.add_threadinfo_collection_packets() +ret = self.expect_gdbremote_sequence() +self.reset_test_sequence() + +pidtids = set(self.parse_threadinfo_packets(ret)) +self.assertEqual(len(pidtids), 4) +# first, save register values from all the threads +thread_regs = {} +for pidtid in pidtids: +for regno in range(256): +self.test_sequence.add_log_lines( +["read packet: $Hgp{:x}.{:x}#00".format(*pidtid), + "send packet: $OK#00", + "read packet: $p{:x}#00".format(regno), + {"direction": "send", + "regex": r"^[$](.+)#.*$", + "capture": {1: "data"}}, + ], True) +ret = self.expect_gdbremote_sequence() +data = ret.get("data") +self.assertIsNotNone(data) +# ignore registers shorter than 32 bits (this also catches +# "Exx" errors) +if len(data) >= 8: +break +else: +self.skipTest("no usable register found") +thread_regs[pidtid] = (regno, data) + +vals = set(x[1] for x in thread_regs.values()) +# NB: cheap hack to make the loop below easier +new_val = next(iter(vals)) + +# then, start altering them and verify that we don't unexpectedly +# change the value from another thread +for pidtid in pidtids: +old_val = thread_regs[pidtid] +regno = old_val[0] +old_val_length = len(old_val[1]) +# generate a unique new_val +while new_val in vals: +new_val = ('{{:0{}x}}'.format(old_val_length) + .format(random.getrandbits(old_val_length*4))) +vals.add(new_val) + +self.test_sequence.add_log_lines( +["read packet: $Hgp{:x}.{:x}#00".format(*pidtid), + "send packet: $OK#00", + "read packet: $p{:x}#00".format(regno), + {"direction": "send", + "regex": r"^[$](.+)#.*$", + "capture": {1: "data"}}, +
[Lldb-commits] [lldb] 75757c8 - [lldb] [llgs] Support multiprocess in qfThreadInfo
Author: Michał Górny Date: 2022-06-24T17:20:24+02:00 New Revision: 75757c86c695a6b4695458343637b3c4fe86def6 URL: https://github.com/llvm/llvm-project/commit/75757c86c695a6b4695458343637b3c4fe86def6 DIFF: https://github.com/llvm/llvm-project/commit/75757c86c695a6b4695458343637b3c4fe86def6.diff LOG: [lldb] [llgs] Support multiprocess in qfThreadInfo Update the `qfThreadInfo` handler to report threads of all debugged processes and include PIDs when in multiprocess mode. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128152 Added: Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py index d1d265d8852b5..eff6dd6d53007 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py @@ -284,9 +284,14 @@ def parse_threadinfo_response(response_packet): response_packet = _STRIP_COMMAND_PREFIX_M_REGEX.sub("", response_packet) response_packet = _STRIP_CHECKSUM_REGEX.sub("", response_packet) -# Return list of thread ids -return [int(thread_id_hex, 16) for thread_id_hex in response_packet.split( -",") if len(thread_id_hex) > 0] +for tid in response_packet.split(","): +if not tid: +continue +if tid.startswith("p"): +pid, _, tid = tid.partition(".") +yield (int(pid[1:], 16), int(tid, 16)) +else: +yield int(tid, 16) def unpack_endian_binary_string(endian, value_string): diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index f6b61f521206b..8c26032cc90db 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1974,38 +1974,46 @@ GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo( return SendPacketNoLock(response.GetString()); } -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo( -StringExtractorGDBRemote ) { +void GDBRemoteCommunicationServerLLGS::AddProcessThreads( +StreamGDBRemote , NativeProcessProtocol , bool _any) { Log *log = GetLog(LLDBLog::Thread); - // Fail if we don't have a current process. - if (!m_current_process || - (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) { -LLDB_LOG(log, "no process ({0}), returning OK", - m_current_process ? "invalid process id" - : "null m_current_process"); -return SendOKResponse(); - } - - StreamGDBRemote response; - response.PutChar('m'); + lldb::pid_t pid = process.GetID(); + if (pid == LLDB_INVALID_PROCESS_ID) +return; - LLDB_LOG(log, "starting thread iteration"); + LLDB_LOG(log, "iterating over threads of process {0}", process.GetID()); NativeThreadProtocol *thread; uint32_t thread_index; - for (thread_index = 0, - thread = m_current_process->GetThreadAtIndex(thread_index); - thread; ++thread_index, - thread = m_current_process->GetThreadAtIndex(thread_index)) { -LLDB_LOG(log, "iterated thread {0}(tid={2})", thread_index, + for (thread_index = 0, thread = process.GetThreadAtIndex(thread_index); + thread; + ++thread_index, thread = process.GetThreadAtIndex(thread_index)) { +LLDB_LOG(log, "iterated thread {0} (tid={1})", thread_index, thread->GetID()); -if (thread_index > 0) - response.PutChar(','); -response.Printf("%" PRIx64, thread->GetID()); +response.PutChar(had_any ? ',' : 'm'); +if (bool(m_extensions_supported & + NativeProcessProtocol::Extension::multiprocess)) + response.Format("p{0:x-}.", pid); +response.Format("{0:x-}", thread->GetID()); +had_any = true; } +} - LLDB_LOG(log, "finished thread iteration"); +GDBRemoteCommunication::PacketResult +GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo( +StringExtractorGDBRemote ) { + assert(m_debugged_processes.size() == 1 || + bool(m_extensions_supported & + NativeProcessProtocol::Extension::multiprocess)); + + bool had_any = false; + StreamGDBRemote response; + + for (auto _ptr : m_debugged_processes) +AddProcessThreads(response, *pid_ptr.second, had_any); + + if (!had_any) +response.PutChar('l'); return
[Lldb-commits] [lldb] 0481d8e - [lldb] [llgs] Add a test for multiprocess memory read/write
Author: Michał Górny Date: 2022-06-24T17:20:24+02:00 New Revision: 0481d8efa92f4508e847046b748c17ace1813272 URL: https://github.com/llvm/llvm-project/commit/0481d8efa92f4508e847046b748c17ace1813272 DIFF: https://github.com/llvm/llvm-project/commit/0481d8efa92f4508e847046b748c17ace1813272.diff LOG: [lldb] [llgs] Add a test for multiprocess memory read/write Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128150 Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index ec6ae2575f4e3..31dd20b475c58 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -553,3 +553,90 @@ def test_vCont_all_processes_implicit(self): "send packet: $E03#00", ], True) self.expect_gdbremote_sequence() + +@add_test_categories(["fork"]) +def test_memory_read_write(self): +self.build() +INITIAL_DATA = "Initial message" +self.prep_debug_monitor_and_inferior( +inferior_args=["set-message:{}".format(INITIAL_DATA), + "get-data-address-hex:g_message", + "fork", + "print-message:", + "trap", + ]) +self.add_qSupported_packets(["multiprocess+", + "fork-events+"]) +ret = self.expect_gdbremote_sequence() +self.assertIn("fork-events+", ret["qSupported_response"]) +self.reset_test_sequence() + +# continue and expect fork +self.test_sequence.add_log_lines([ +"read packet: $c#00", +{"type": "output_match", + "regex": self.maybe_strict_output_regex(r"data address: 0x([0-9a-fA-F]+)\r\n"), + "capture": {1: "addr"}}, +{"direction": "send", "regex": self.fork_regex.format("fork"), + "capture": self.fork_capture}, +], True) +ret = self.expect_gdbremote_sequence() +pidtids = { +"parent": (ret["parent_pid"], ret["parent_tid"]), +"child": (ret["child_pid"], ret["child_tid"]), +} +addr = ret["addr"] +self.reset_test_sequence() + +for name, pidtid in pidtids.items(): +self.test_sequence.add_log_lines( +["read packet: $Hgp{}.{}#00".format(*pidtid), + "send packet: $OK#00", + # read the current memory contents + "read packet: $m{},{:x}#00".format(addr, +len(INITIAL_DATA) + 1), + {"direction": "send", + "regex": r"^[$](.+)#.*$", + "capture": {1: "data"}}, + # write a new value + "read packet: $M{},{:x}:{}#00".format(addr, + len(name) + 1, + seven.hexlify( + name + "\0")), + "send packet: $OK#00", + # resume the process and wait for the trap + "read packet: $Hcp{}.{}#00".format(*pidtid), + "send packet: $OK#00", + "read packet: $c#00", + {"type": "output_match", + "regex": self.maybe_strict_output_regex(r"message: (.*)\r\n"), + "capture": {1: "printed_message"}}, + {"direction": "send", + "regex": "^[$]T05thread:p{}.{}.*".format(*pidtid), + }, + ], True) +ret = self.expect_gdbremote_sequence() +data = seven.unhexlify(ret["data"]) +self.assertEqual(data, INITIAL_DATA + "\0") +self.assertEqual(ret["printed_message"], name); +self.reset_test_sequence() + +# we do the second round separately to make sure that initial data +# is correctly preserved while writing into the first process + +for name, pidtid in pidtids.items(): +self.test_sequence.add_log_lines( +["read packet: $Hgp{}.{}#00".format(*pidtid), + "send packet: $OK#00", + # read the current memory contents + "read packet: $m{},{:x}#00".format(addr, +len(name) + 1), + {"direction": "send", + "regex": r"^[$](.+)#.*$", + "capture": {1: "data"}}, + ], True) +ret = self.expect_gdbremote_sequence() +self.assertIsNotNone(ret.get("data")) +data =
[Lldb-commits] [lldb] a342279 - [lldb] [llgs] Support resuming one process with PID!=current via vCont
Author: Michał Górny Date: 2022-06-24T17:20:23+02:00 New Revision: a3422793e0643fa849ff178d87fc706c81b734b7 URL: https://github.com/llvm/llvm-project/commit/a3422793e0643fa849ff178d87fc706c81b734b7 DIFF: https://github.com/llvm/llvm-project/commit/a3422793e0643fa849ff178d87fc706c81b734b7.diff LOG: [lldb] [llgs] Support resuming one process with PID!=current via vCont Extend vCont function to support resuming a process with an arbitrary PID, that could be different than the one selected via Hc (or no process at all may be selected). Resuming more than one process simultaneously is not supported yet. Remove the ReadTid() method that was only used by Handle_vCont(), and furthermore it was wrongly using m_current_process rather than m_continue_process. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127862 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/source/Utility/StringExtractorGDBRemote.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 1ff0b7fe4ee5d..f6b61f521206b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1674,12 +1674,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont( return SendIllFormedResponse(packet, "Missing action from vCont package"); } - // Check if this is all continue (no options or ";c"). - if (::strcmp(packet.Peek(), ";c") == 0) { -// Move past the ';', then do a simple 'c'. -packet.SetFilePos(packet.GetFilePos() + 1); -return Handle_c(packet); - } else if (::strcmp(packet.Peek(), ";s") == 0) { + if (::strcmp(packet.Peek(), ";s") == 0) { // Move past the ';', then do a simple 's'. packet.SetFilePos(packet.GetFilePos() + 1); return Handle_s(packet); @@ -1688,13 +1683,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont( return SendOKResponse(); } - // Ensure we have a native process. - if (!m_continue_process) { -LLDB_LOG(log, "no debugged process"); -return SendErrorResponse(0x36); - } - - ResumeActionList thread_actions; + std::unordered_map thread_actions; while (packet.GetBytesLeft() && *packet.Peek() == ';') { // Skip the semi-colon. @@ -1737,32 +1726,62 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont( break; } +lldb::pid_t pid = StringExtractorGDBRemote::AllProcesses; +lldb::tid_t tid = StringExtractorGDBRemote::AllThreads; + // Parse out optional :{thread-id} value. if (packet.GetBytesLeft() && (*packet.Peek() == ':')) { // Consume the separator. packet.GetChar(); - llvm::Expected tid_ret = - ReadTid(packet, /*allow_all=*/true, m_continue_process->GetID()); - if (!tid_ret) -return SendErrorResponse(tid_ret.takeError()); + auto pid_tid = packet.GetPidTid(StringExtractorGDBRemote::AllProcesses); + if (!pid_tid) +return SendIllFormedResponse(packet, "Malformed thread-id"); - thread_action.tid = tid_ret.get(); - if (thread_action.tid == StringExtractorGDBRemote::AllThreads) -thread_action.tid = LLDB_INVALID_THREAD_ID; + pid = pid_tid->first; + tid = pid_tid->second; } -thread_actions.Append(thread_action); - } +if (pid == StringExtractorGDBRemote::AllProcesses) { + if (m_debugged_processes.size() > 1) +return SendIllFormedResponse( +packet, "Resuming multiple processes not supported yet"); + if (!m_continue_process) { +LLDB_LOG(log, "no debugged process"); +return SendErrorResponse(0x36); + } + pid = m_continue_process->GetID(); +} - Status error = m_continue_process->Resume(thread_actions); - if (error.Fail()) { -LLDB_LOG(log, "vCont failed for process {0}: {1}", - m_continue_process->GetID(), error); -return SendErrorResponse(GDBRemoteServerError::eErrorResume); +if (tid == StringExtractorGDBRemote::AllThreads) + tid = LLDB_INVALID_THREAD_ID; + +thread_action.tid = tid; + +thread_actions[pid].Append(thread_action); } - LLDB_LOG(log, "continued process {0}", m_continue_process->GetID()); + assert(thread_actions.size() >= 1); + if (thread_actions.size() > 1) +return SendIllFormedResponse( +packet, "Resuming multiple processes not supported yet"); + + for (std::pair x : thread_actions) { +auto process_it = m_debugged_processes.find(x.first); +if (process_it == m_debugged_processes.end()) { + LLDB_LOG(log, "vCont failed for process {0}: process
[Lldb-commits] [lldb] 3266b11 - [lldb] [llgs] Add test for resuming via c in multiprocess scenarios
Author: Michał Górny Date: 2022-06-24T17:20:23+02:00 New Revision: 3266b117147db73d1c42668c1033b59a36d8a2f3 URL: https://github.com/llvm/llvm-project/commit/3266b117147db73d1c42668c1033b59a36d8a2f3 DIFF: https://github.com/llvm/llvm-project/commit/3266b117147db73d1c42668c1033b59a36d8a2f3.diff LOG: [lldb] [llgs] Add test for resuming via c in multiprocess scenarios Add a test verifying that it is possible to resume a single process via the `c` packet when multiple processes are being debugged. This includes a tiny change to the test program — when `fork()` is called, the child process is no longer terminated immediately but continues performing the same tasks as queued for the parent. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127755 Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py lldb/test/API/tools/lldb-server/main.cpp Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index a49a5b42c2ba8..f5f088f506848 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -353,3 +353,81 @@ def test_vkill_parent(self): @add_test_categories(["fork"]) def test_vkill_both(self): self.vkill_test(kill_parent=True, kill_child=True) + +def resume_one_test(self, run_order): +self.build() +self.prep_debug_monitor_and_inferior(inferior_args=["fork", "trap"]) +self.add_qSupported_packets(["multiprocess+", + "fork-events+"]) +ret = self.expect_gdbremote_sequence() +self.assertIn("fork-events+", ret["qSupported_response"]) +self.reset_test_sequence() + +# continue and expect fork +self.test_sequence.add_log_lines([ +"read packet: $c#00", +{"direction": "send", "regex": self.fork_regex.format("fork"), + "capture": self.fork_capture}, +], True) +ret = self.expect_gdbremote_sequence() +parent_pid = ret["parent_pid"] +parent_tid = ret["parent_tid"] +child_pid = ret["child_pid"] +child_tid = ret["child_tid"] +self.reset_test_sequence() + +parent_expect = [ +"[$]T05thread:p{}.{};.*".format(parent_pid, parent_tid), +"[$]W00;process:{}#.*".format(parent_pid), +] +child_expect = [ +"[$]T05thread:p{}.{};.*".format(child_pid, child_tid), +"[$]W00;process:{}#.*".format(child_pid), +] + +for x in run_order: +if x == "parent": +pidtid = (parent_pid, parent_tid) +expect = parent_expect.pop(0) +elif x == "child": +pidtid = (child_pid, child_tid) +expect = child_expect.pop(0) +else: +assert False, "unexpected x={}".format(x) + +self.test_sequence.add_log_lines([ +# continue the selected process +"read packet: $Hcp{}.{}#00".format(*pidtid), +"send packet: $OK#00", +"read packet: $c#00", +{"direction": "send", "regex": expect}, +], True) +# if at least one process remained, check both PIDs +if parent_expect or child_expect: +self.test_sequence.add_log_lines([ +"read packet: $Hgp{}.{}#00".format(parent_pid, parent_tid), +"send packet: ${}#00".format("OK" if parent_expect else "Eff"), +"read packet: $Hgp{}.{}#00".format(child_pid, child_tid), +"send packet: ${}#00".format("OK" if child_expect else "Eff"), +], True) +self.expect_gdbremote_sequence() + +@add_test_categories(["fork"]) +def test_c_parent(self): +self.resume_one_test(run_order=["parent", "parent"]) + +@add_test_categories(["fork"]) +def test_c_child(self): +self.resume_one_test(run_order=["child", "child"]) + +@add_test_categories(["fork"]) +def test_c_parent_then_child(self): +self.resume_one_test(run_order=["parent", "parent", "child", "child"]) + +@add_test_categories(["fork"]) +def test_c_child_then_parent(self): +self.resume_one_test(run_order=["child", "child", "parent", "parent"]) + +@add_test_categories(["fork"]) +def test_c_interspersed(self): +self.resume_one_test(run_order=["parent", "child", "parent", "child"]) diff --git a/lldb/test/API/tools/lldb-server/main.cpp b/lldb/test/API/tools/lldb-server/main.cpp index 0383acc68fccf..9907a09dfc7d2 100644 --- a/lldb/test/API/tools/lldb-server/main.cpp +++ b/lldb/test/API/tools/lldb-server/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@
[Lldb-commits] [lldb] c18784b - [lldb] [llgs] Implement the vKill packet
Author: Michał Górny Date: 2022-06-24T17:20:23+02:00 New Revision: c18784ba330ac0f57e6ec433cfa8317349c445ff URL: https://github.com/llvm/llvm-project/commit/c18784ba330ac0f57e6ec433cfa8317349c445ff DIFF: https://github.com/llvm/llvm-project/commit/c18784ba330ac0f57e6ec433cfa8317349c445ff.diff LOG: [lldb] [llgs] Implement the vKill packet Implement the support for the vKill packet. This is the modern packet used by the GDB Remote Serial Protocol to kill one of the debugged processes. Unlike the `k` packet, it has well-defined semantics. The `vKill` packet takes the PID of the process to kill, and always replies with an `OK` reply (rather than the exit status, as LLGS does for `k` packets at the moment). Additionally, unlike the `k` packet it does not cause the connection to be terminated once the last process is killed — the client needs to close it explicitly. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127667 Added: Modified: lldb/include/lldb/Utility/StringExtractorGDBRemote.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/source/Utility/StringExtractorGDBRemote.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h index 2a63212e9d287..c32ce0389116e 100644 --- a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h +++ b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h @@ -136,6 +136,7 @@ class StringExtractorGDBRemote : public StringExtractor { eServerPacketType_vAttachName, eServerPacketType_vCont, eServerPacketType_vCont_actions, // vCont? +eServerPacketType_vKill, eServerPacketType_vRun, eServerPacketType_stop_reason, // '?' diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 434fb50862f8b..1ff0b7fe4ee5d 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -232,6 +232,10 @@ void GDBRemoteCommunicationServerLLGS::RegisterPacketHandlers() { return this->Handle_k(packet); }); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vKill, + ::Handle_vKill); + RegisterMemberFunctionHandler( StringExtractorGDBRemote::eServerPacketType_qLLDBSaveCore, ::Handle_qSaveCore); @@ -482,6 +486,10 @@ GDBRemoteCommunicationServerLLGS::SendWResponse( LLDB_LOG(log, "pid = {0}, returning exit type {1}", process->GetID(), *wait_status); + // If the process was killed through vKill, return "OK". + if (m_vkilled_processes.find(process->GetID()) != m_vkilled_processes.end()) +return SendOKResponse(); + StreamGDBRemote response; response.Format("{0:g}", *wait_status); if (bool(m_extensions_supported & NativeProcessProtocol::Extension::multiprocess)) @@ -1049,9 +1057,13 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited( lldb::pid_t pid = process->GetID(); m_mainloop.AddPendingCallback([this, pid](MainLoopBase ) { m_debugged_processes.erase(pid); +auto vkill_it = m_vkilled_processes.find(pid); +if (vkill_it != m_vkilled_processes.end()) + m_vkilled_processes.erase(vkill_it); +// Terminate the main loop only if vKill has not been used. // When running in non-stop mode, wait for the vStopped to clear // the notification queue. -if (m_debugged_processes.empty() && !m_non_stop) { +else if (m_debugged_processes.empty() && !m_non_stop) { // Close the pipe to the inferior terminal i/o if we launched it and set // one up. MaybeCloseInferiorTerminalConnection(); @@ -1442,6 +1454,30 @@ GDBRemoteCommunicationServerLLGS::Handle_k(StringExtractorGDBRemote ) { return SendContinueSuccessResponse(); } +GDBRemoteCommunication::PacketResult +GDBRemoteCommunicationServerLLGS::Handle_vKill( +StringExtractorGDBRemote ) { + StopSTDIOForwarding(); + + packet.SetFilePos(6); // vKill; + uint32_t pid = packet.GetU32(LLDB_INVALID_PROCESS_ID, 16); + if (pid == LLDB_INVALID_PROCESS_ID) +return SendIllFormedResponse(packet, + "vKill failed to parse the process id"); + + auto it = m_debugged_processes.find(pid); + if (it == m_debugged_processes.end()) +return SendErrorResponse(42); + + Status error = it->second->Kill(); + if (error.Fail()) +return SendErrorResponse(error.ToError()); + + // OK response is sent when the process dies. + m_vkilled_processes.insert(pid); + return
[Lldb-commits] [lldb] e8fe7e9 - [lldb] [llgs] Make `k` kill all processes, and fix multiple exits
Author: Michał Górny Date: 2022-06-24T17:20:23+02:00 New Revision: e8fe7e930a45764cbb88d9c3fa91ef7dc1ebcc97 URL: https://github.com/llvm/llvm-project/commit/e8fe7e930a45764cbb88d9c3fa91ef7dc1ebcc97 DIFF: https://github.com/llvm/llvm-project/commit/e8fe7e930a45764cbb88d9c3fa91ef7dc1ebcc97.diff LOG: [lldb] [llgs] Make `k` kill all processes, and fix multiple exits Modify the behavior of the `k` packet to kill all inferiors rather than just the current one. The specification leaves the exact behavior of this packet up to the implementation but since vKill is specifically meant to be used to kill a single process, it seems logical to use `k` to provide the alternate function of killing all of them. Move starting stdio forwarding from the "running" response to the packet handlers that trigger the process to start. This avoids attempting to start it multiple times when multiple processes are killed on Linux which implicitly causes LLGS to receive "started" events for all of them. This is probably also more correct as the ability to send "O" packets is implied by the continue-like command being issued (and therefore the client waiting for responses) rather than the start notification. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127500 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 1cddb5b29c595..434fb50862f8b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1041,17 +1041,26 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited( __FUNCTION__, process->GetID()); } - // Close the pipe to the inferior terminal i/o if we launched it and set one - // up. - MaybeCloseInferiorTerminalConnection(); - - // When running in non-stop mode, wait for the vStopped to clear - // the notification queue. - if (!m_non_stop) { -// We are ready to exit the debug monitor. -m_exit_now = true; -m_mainloop.RequestTermination(); - } + if (m_current_process == process) +m_current_process = nullptr; + if (m_continue_process == process) +m_continue_process = nullptr; + + lldb::pid_t pid = process->GetID(); + m_mainloop.AddPendingCallback([this, pid](MainLoopBase ) { +m_debugged_processes.erase(pid); +// When running in non-stop mode, wait for the vStopped to clear +// the notification queue. +if (m_debugged_processes.empty() && !m_non_stop) { + // Close the pipe to the inferior terminal i/o if we launched it and set + // one up. + MaybeCloseInferiorTerminalConnection(); + + // We are ready to exit the debug monitor. + m_exit_now = true; + loop.RequestTermination(); +} + }); } void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped( @@ -1094,7 +1103,6 @@ void GDBRemoteCommunicationServerLLGS::ProcessStateChanged( switch (state) { case StateType::eStateRunning: -StartSTDIOForwarding(); break; case StateType::eStateStopped: @@ -1219,7 +1227,7 @@ void GDBRemoteCommunicationServerLLGS::StartSTDIOForwarding() { return; Status error; - lldbassert(!m_stdio_handle_up); + assert(!m_stdio_handle_up); m_stdio_handle_up = m_mainloop.RegisterReadObject( m_stdio_communication.GetConnection()->GetReadObject(), [this](MainLoopBase &) { SendProcessOutput(); }, error); @@ -1228,10 +1236,7 @@ void GDBRemoteCommunicationServerLLGS::StartSTDIOForwarding() { // Not much we can do about the failure. Log it and continue without // forwarding. if (Log *log = GetLog(LLDBLog::Process)) - LLDB_LOGF(log, -"GDBRemoteCommunicationServerLLGS::%s Failed to set up stdio " -"forwarding: %s", -__FUNCTION__, error.AsCString()); + LLDB_LOG(log, "Failed to set up stdio forwarding: {0}", error); } } @@ -1416,15 +1421,19 @@ GDBRemoteCommunicationServerLLGS::Handle_k(StringExtractorGDBRemote ) { StopSTDIOForwarding(); - if (!m_current_process) { + if (m_debugged_processes.empty()) { LLDB_LOG(log, "No debugged process found."); return PacketResult::Success; } - Status error = m_current_process->Kill(); - if (error.Fail()) -LLDB_LOG(log, "Failed to kill debugged process {0}: {1}", - m_current_process->GetID(), error); + for (auto it = m_debugged_processes.begin(); it != m_debugged_processes.end(); + ++it) { +LLDB_LOG(log, "Killing process {0}", it->first); +Status error = it->second->Kill(); +if
[Lldb-commits] [lldb] 5e9aed1 - [lldb] [test] Mark TestNonStop as LLGS-specific
Author: Michał Górny Date: 2022-06-22T05:36:30+02:00 New Revision: 5e9aed1be5a5608d97c2ec3ac87698a8257b0ea7 URL: https://github.com/llvm/llvm-project/commit/5e9aed1be5a5608d97c2ec3ac87698a8257b0ea7 DIFF: https://github.com/llvm/llvm-project/commit/5e9aed1be5a5608d97c2ec3ac87698a8257b0ea7.diff LOG: [lldb] [test] Mark TestNonStop as LLGS-specific Thanks for Med Ismail Bennani for reporting the debugserver failures. Added: Modified: lldb/test/API/tools/lldb-server/TestNonStop.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestNonStop.py b/lldb/test/API/tools/lldb-server/TestNonStop.py index 2317d7061112..ebe66366b173 100644 --- a/lldb/test/API/tools/lldb-server/TestNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestNonStop.py @@ -9,6 +9,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @skipIfWindows # no SIGSEGV support +@add_test_categories(["llgs"]) def test_run(self): self.build() self.set_inferior_startup_launch() @@ -116,6 +117,7 @@ def test_run(self): # finally, verify that all threads have started self.assertEqual(len(all_threads), thread_num + 1) +@add_test_categories(["llgs"]) def test_vCtrlC(self): self.build() self.set_inferior_startup_launch() @@ -134,6 +136,7 @@ def test_vCtrlC(self): ], True) self.expect_gdbremote_sequence() +@add_test_categories(["llgs"]) def test_exit(self): self.build() self.set_inferior_startup_launch() @@ -150,6 +153,7 @@ def test_exit(self): self.expect_gdbremote_sequence() @skipIfWindows # no clue, the result makes zero sense +@add_test_categories(["llgs"]) def test_exit_query(self): self.build() self.set_inferior_startup_launch() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 80c04c6 - [lldb] [llgs] Attempt to fix LLGS tests on Windows
Author: Michał Górny Date: 2022-06-21T20:12:07+02:00 New Revision: 80c04c664a2a1900c5fdbf88c2c11e3f4f4ebf71 URL: https://github.com/llvm/llvm-project/commit/80c04c664a2a1900c5fdbf88c2c11e3f4f4ebf71 DIFF: https://github.com/llvm/llvm-project/commit/80c04c664a2a1900c5fdbf88c2c11e3f4f4ebf71.diff LOG: [lldb] [llgs] Attempt to fix LLGS tests on Windows Sponsored by: The FreeBSD Foundation Added: Modified: lldb/test/API/tools/lldb-server/TestNonStop.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestNonStop.py b/lldb/test/API/tools/lldb-server/TestNonStop.py index f2647995a778..2317d7061112 100644 --- a/lldb/test/API/tools/lldb-server/TestNonStop.py +++ b/lldb/test/API/tools/lldb-server/TestNonStop.py @@ -1,3 +1,4 @@ +from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * import gdbremote_testcase @@ -7,6 +8,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) +@skipIfWindows # no SIGSEGV support def test_run(self): self.build() self.set_inferior_startup_launch() @@ -127,7 +129,7 @@ def test_vCtrlC(self): "read packet: $vCtrlC#00", "send packet: $OK#00", {"direction": "send", - "regex": r"^%Stop:T13", + "regex": r"^%Stop:T", }, ], True) self.expect_gdbremote_sequence() @@ -147,6 +149,7 @@ def test_exit(self): ], True) self.expect_gdbremote_sequence() +@skipIfWindows # no clue, the result makes zero sense def test_exit_query(self): self.build() self.set_inferior_startup_launch() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 13eb5b3 - [lldb] [llgs] Add a test for detach-all packet
Author: Michał Górny Date: 2022-06-21T19:47:31+02:00 New Revision: 13eb5b3455fbeb959ab36974e17ba03222d6a4d0 URL: https://github.com/llvm/llvm-project/commit/13eb5b3455fbeb959ab36974e17ba03222d6a4d0 DIFF: https://github.com/llvm/llvm-project/commit/13eb5b3455fbeb959ab36974e17ba03222d6a4d0.diff LOG: [lldb] [llgs] Add a test for detach-all packet Add a test verifying that plain 'D' packet correctly detaches all processes. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127291 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 2a62e7a1fd0e..1cddb5b29c59 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -3375,6 +3375,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vRun( GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote ) { + Log *log = GetLog(LLDBLog::Process); StopSTDIOForwarding(); lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; @@ -3398,6 +3399,9 @@ GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote ) { for (auto it = m_debugged_processes.begin(); it != m_debugged_processes.end();) { if (pid == LLDB_INVALID_PROCESS_ID || pid == it->first) { + LLDB_LOGF(log, +"GDBRemoteCommunicationServerLLGS::%s detaching %" PRId64, +__FUNCTION__, it->first); if (llvm::Error e = it->second->Detach().ToError()) detach_error = llvm::joinErrors(std::move(detach_error), std::move(e)); else { diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index c0f5629f97fc..bbd5912edf7d 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -222,3 +222,43 @@ def test_detach_current(self): "send packet: $E44#00", ], True) self.expect_gdbremote_sequence() + +@add_test_categories(["fork"]) +def test_detach_all(self): +self.build() +self.prep_debug_monitor_and_inferior(inferior_args=["fork"]) +self.add_qSupported_packets(["multiprocess+", + "fork-events+"]) +ret = self.expect_gdbremote_sequence() +self.assertIn("fork-events+", ret["qSupported_response"]) +self.reset_test_sequence() + +# continue and expect fork +self.test_sequence.add_log_lines([ +"read packet: $c#00", +{"direction": "send", "regex": self.fork_regex.format("fork"), + "capture": self.fork_capture}, +], True) +ret = self.expect_gdbremote_sequence() +parent_pid = ret["parent_pid"] +parent_tid = ret["parent_tid"] +child_pid = ret["child_pid"] +child_tid = ret["child_tid"] +self.reset_test_sequence() + +self.test_sequence.add_log_lines([ +# double-check our PIDs +"read packet: $Hgp{}.{}#00".format(parent_pid, parent_tid), +"send packet: $OK#00", +"read packet: $Hgp{}.{}#00".format(child_pid, child_tid), +"send packet: $OK#00", +# detach all processes +"read packet: $D#00", +"send packet: $OK#00", +# verify that both PIDs are invalid now +"read packet: $Hgp{}.{}#00".format(parent_pid, parent_tid), +"send packet: $Eff#00", +"read packet: $Hgp{}.{}#00".format(child_pid, child_tid), +"send packet: $Eff#00", +], True) +self.expect_gdbremote_sequence() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 313d9c1 - [lldb] [llgs] Refactor fork/vfork tests, verify state
Author: Michał Górny Date: 2022-06-21T19:47:30+02:00 New Revision: 313d9c1519b7f93b3dcb9ae1d535adf7b0da821d URL: https://github.com/llvm/llvm-project/commit/313d9c1519b7f93b3dcb9ae1d535adf7b0da821d DIFF: https://github.com/llvm/llvm-project/commit/313d9c1519b7f93b3dcb9ae1d535adf7b0da821d.diff LOG: [lldb] [llgs] Refactor fork/vfork tests, verify state Refactor the fork and vfork tests to reuse the code better, avoid unnecessary regexps and avoid unnecessary conversions between hex-strings and integers. Verify the server state after detaching. In particular, verify that the detached process' PID/TID pair is no longer valid, and that the correct process remains running. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127290 Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 4d3ab1efeac7..c0f5629f97fc 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -5,6 +5,12 @@ class TestGdbRemoteFork(gdbremote_testcase.GdbRemoteTestCaseBase): +fork_regex = ("[$]T05thread:p([0-9a-f]+)[.]([0-9a-f]+);.*" + "{}:p([0-9a-f]+)[.]([0-9a-f]+).*") +fork_capture = {1: "parent_pid", 2: "parent_tid", +3: "child_pid", 4: "child_tid"} +procinfo_regex = "[$]pid:([0-9a-f]+);.*" + @add_test_categories(["fork"]) def test_fork_multithreaded(self): self.build() @@ -15,26 +21,19 @@ def test_fork_multithreaded(self): self.reset_test_sequence() # continue and expect fork -fork_regex = "[$]T05.*;fork:p([0-9a-f]+)[.]([0-9a-f]+).*" self.test_sequence.add_log_lines([ "read packet: $c#00", -{"direction": "send", "regex": fork_regex, - "capture": {1: "pid", 2: "tid"}}, +{"direction": "send", "regex": self.fork_regex.format("fork"), + "capture": self.fork_capture}, ], True) ret = self.expect_gdbremote_sequence() -pid = int(ret["pid"], 16) +child_pid = ret["child_pid"] self.reset_test_sequence() # detach the forked child self.test_sequence.add_log_lines([ -"read packet: $D;{:x}#00".format(pid), -{"direction": "send", "regex": r"[$]OK#.*"}, -], True) -ret = self.expect_gdbremote_sequence() -self.reset_test_sequence() - -# resume the parent -self.test_sequence.add_log_lines([ +"read packet: $D;{}#00".format(child_pid), +"send packet: $OK#00", "read packet: $k#00", ], True) self.expect_gdbremote_sequence() @@ -49,45 +48,59 @@ def fork_and_detach_test(self, variant): self.reset_test_sequence() # continue and expect fork -fork_regex = "[$]T05.*;{}:p([0-9a-f]+)[.]([0-9a-f]+).*".format(variant) self.test_sequence.add_log_lines([ "read packet: $c#00", -{"direction": "send", "regex": fork_regex, - "capture": {1: "pid", 2: "tid"}}, +{"direction": "send", "regex": self.fork_regex.format(variant), + "capture": self.fork_capture}, ], True) ret = self.expect_gdbremote_sequence() -pid = int(ret["pid"], 16) +parent_pid = ret["parent_pid"] +parent_tid = ret["parent_tid"] +child_pid = ret["child_pid"] +child_tid = ret["child_tid"] self.reset_test_sequence() # detach the forked child self.test_sequence.add_log_lines([ -"read packet: $D;{:x}#00".format(pid), -{"direction": "send", "regex": r"[$]OK#.*"}, +"read packet: $D;{}#00".format(child_pid), +"send packet: $OK#00", +# verify that the current process is correct +"read packet: $qC#00", +"send packet: $QC{}#00".format(parent_tid), +# verify that the correct processes are detached/available +"read packet: $Hgp{}.{}#00".format(child_pid, child_tid), +"send packet: $Eff#00", +"read packet: $Hgp{}.{}#00".format(parent_pid, parent_tid), +"send packet: $OK#00", ], True) -ret = self.expect_gdbremote_sequence() +self.expect_gdbremote_sequence() self.reset_test_sequence() +return parent_pid, parent_tid @add_test_categories(["fork"]) def test_fork(self): -self.fork_and_detach_test("fork") +parent_pid, _ = self.fork_and_detach_test("fork") # resume the parent self.test_sequence.add_log_lines([ "read packet: $c#00", -{"direction": "send", "regex":
[Lldb-commits] [lldb] d6b3de7 - [lldb] [llgs] Fix signo sent with fork/vfork/vforkdone events
Author: Michał Górny Date: 2022-06-21T19:47:30+02:00 New Revision: d6b3de72566f874f198b2ddcecbec53e95c623fe URL: https://github.com/llvm/llvm-project/commit/d6b3de72566f874f198b2ddcecbec53e95c623fe DIFF: https://github.com/llvm/llvm-project/commit/d6b3de72566f874f198b2ddcecbec53e95c623fe.diff LOG: [lldb] [llgs] Fix signo sent with fork/vfork/vforkdone events Fix ThreadStopInfo struct to include the signal number for all events. Since signo was not included in the details for fork, vfork and vforkdone stops, the code incidentally referenced the wrong union member, resulting in wrong signo being sent. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127193 Added: Modified: lldb/include/lldb/Host/Debug.h lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py lldb/tools/debugserver/source/RNBRemote.cpp Removed: diff --git a/lldb/include/lldb/Host/Debug.h b/lldb/include/lldb/Host/Debug.h index 622b7200edbc6..56a6efd1b4d6c 100644 --- a/lldb/include/lldb/Host/Debug.h +++ b/lldb/include/lldb/Host/Debug.h @@ -130,12 +130,8 @@ class ResumeActionList { struct ThreadStopInfo { lldb::StopReason reason; + uint32_t signo; union { -// eStopReasonSignal -struct { - uint32_t signo; -} signal; - // eStopReasonException struct { uint64_t type; diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp index a75668f3b5c7f..8e6399bcf9c79 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp @@ -81,7 +81,7 @@ void NativeThreadFreeBSD::SetStoppedBySignal(uint32_t signo, SetStopped(); m_stop_info.reason = StopReason::eStopReasonSignal; - m_stop_info.details.signal.signo = signo; + m_stop_info.signo = signo; m_stop_description.clear(); if (info) { @@ -100,19 +100,19 @@ void NativeThreadFreeBSD::SetStoppedBySignal(uint32_t signo, void NativeThreadFreeBSD::SetStoppedByBreakpoint() { SetStopped(); m_stop_info.reason = StopReason::eStopReasonBreakpoint; - m_stop_info.details.signal.signo = SIGTRAP; + m_stop_info.signo = SIGTRAP; } void NativeThreadFreeBSD::SetStoppedByTrace() { SetStopped(); m_stop_info.reason = StopReason::eStopReasonTrace; - m_stop_info.details.signal.signo = SIGTRAP; + m_stop_info.signo = SIGTRAP; } void NativeThreadFreeBSD::SetStoppedByExec() { SetStopped(); m_stop_info.reason = StopReason::eStopReasonExec; - m_stop_info.details.signal.signo = SIGTRAP; + m_stop_info.signo = SIGTRAP; } void NativeThreadFreeBSD::SetStoppedByWatchpoint(uint32_t wp_index) { @@ -127,7 +127,7 @@ void NativeThreadFreeBSD::SetStoppedByWatchpoint(uint32_t wp_index) { SetStopped(); m_stop_description = ostr.str(); m_stop_info.reason = StopReason::eStopReasonWatchpoint; - m_stop_info.details.signal.signo = SIGTRAP; + m_stop_info.signo = SIGTRAP; } void NativeThreadFreeBSD::SetStoppedByFork(lldb::pid_t child_pid, @@ -135,6 +135,7 @@ void NativeThreadFreeBSD::SetStoppedByFork(lldb::pid_t child_pid, SetStopped(); m_stop_info.reason = StopReason::eStopReasonFork; + m_stop_info.signo = SIGTRAP; m_stop_info.details.fork.child_pid = child_pid; m_stop_info.details.fork.child_tid = child_tid; } @@ -144,6 +145,7 @@ void NativeThreadFreeBSD::SetStoppedByVFork(lldb::pid_t child_pid, SetStopped(); m_stop_info.reason = StopReason::eStopReasonVFork; + m_stop_info.signo = SIGTRAP; m_stop_info.details.fork.child_pid = child_pid; m_stop_info.details.fork.child_tid = child_tid; } @@ -152,13 +154,14 @@ void NativeThreadFreeBSD::SetStoppedByVForkDone() { SetStopped(); m_stop_info.reason = StopReason::eStopReasonVForkDone; + m_stop_info.signo = SIGTRAP; } void NativeThreadFreeBSD::SetStoppedWithNoReason() { SetStopped(); m_stop_info.reason = StopReason::eStopReasonNone; - m_stop_info.details.signal.signo = 0; + m_stop_info.signo = 0; } void NativeThreadFreeBSD::SetStopped() { diff --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp index 47cc6ec19829a..9572f617e60d3 100644 --- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp @@ -48,19 +48,19 @@ void LogThreadStopInfo(Log , const ThreadStopInfo _info, return; case eStopReasonTrace: log.Printf("%s: %s trace, stopping signal 0x%" PRIx32,
[Lldb-commits] [lldb] 5b04eb2 - [lldb] [MainLoop] Support "pending callbacks", to be called once
Author: Michał Górny Date: 2022-06-21T19:47:30+02:00 New Revision: 5b04eb23ae1a4db074b7ddc2e0c136d008fb5bc7 URL: https://github.com/llvm/llvm-project/commit/5b04eb23ae1a4db074b7ddc2e0c136d008fb5bc7 DIFF: https://github.com/llvm/llvm-project/commit/5b04eb23ae1a4db074b7ddc2e0c136d008fb5bc7.diff LOG: [lldb] [MainLoop] Support "pending callbacks", to be called once Support adding a "pending callback" to the main loop, that will be called once after all the pending events are processed. This can be e.g. to defer destroying the process instance until its exit is fully processed, as suggested in D127500. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128253 Added: Modified: lldb/include/lldb/Host/MainLoop.h lldb/include/lldb/Host/MainLoopBase.h lldb/source/Host/common/MainLoop.cpp lldb/unittests/Host/MainLoopTest.cpp Removed: diff --git a/lldb/include/lldb/Host/MainLoop.h b/lldb/include/lldb/Host/MainLoop.h index 94499f5834633..f04ac7359cc18 100644 --- a/lldb/include/lldb/Host/MainLoop.h +++ b/lldb/include/lldb/Host/MainLoop.h @@ -14,6 +14,7 @@ #include "llvm/ADT/DenseMap.h" #include #include +#include #if !HAVE_PPOLL && !HAVE_SYS_EVENT_H && !defined(__ANDROID__) #define SIGNAL_POLLING_UNSUPPORTED 1 @@ -59,6 +60,11 @@ class MainLoop : public MainLoopBase { SignalHandleUP RegisterSignal(int signo, const Callback , Status ); + // Add a pending callback that will be executed once after all the pending + // events are processed. The callback will be executed even if termination + // was requested. + void AddPendingCallback(const Callback ) override; + Status Run() override; // This should only be performed from a callback. Do not attempt to terminate @@ -104,6 +110,7 @@ class MainLoop : public MainLoopBase { llvm::DenseMap m_read_fds; llvm::DenseMap m_signals; + std::vector m_pending_callbacks; #if HAVE_SYS_EVENT_H int m_kqueue; #endif diff --git a/lldb/include/lldb/Host/MainLoopBase.h b/lldb/include/lldb/Host/MainLoopBase.h index 67857b26ac70b..2a2899341a51b 100644 --- a/lldb/include/lldb/Host/MainLoopBase.h +++ b/lldb/include/lldb/Host/MainLoopBase.h @@ -46,6 +46,13 @@ class MainLoopBase { llvm_unreachable("Not implemented"); } + // Add a pending callback that will be executed once after all the pending + // events are processed. The callback will be executed even if termination + // was requested. + virtual void AddPendingCallback(const Callback ) { +llvm_unreachable("Not implemented"); + } + // Waits for registered events and invoke the proper callbacks. Returns when // all callbacks deregister themselves or when someone requests termination. virtual Status Run() { llvm_unreachable("Not implemented"); } diff --git a/lldb/source/Host/common/MainLoop.cpp b/lldb/source/Host/common/MainLoop.cpp index d36587ce2346e..8e384c9266b6b 100644 --- a/lldb/source/Host/common/MainLoop.cpp +++ b/lldb/source/Host/common/MainLoop.cpp @@ -347,6 +347,10 @@ MainLoop::RegisterSignal(int signo, const Callback , Status ) { #endif } +void MainLoop::AddPendingCallback(const Callback ) { + m_pending_callbacks.push_back(callback); +} + void MainLoop::UnregisterReadObject(IOObject::WaitableHandle handle) { bool erased = m_read_fds.erase(handle); UNUSED_IF_ASSERT_DISABLED(erased); @@ -401,6 +405,10 @@ Status MainLoop::Run() { return error; impl.ProcessEvents(); + +for (const Callback : m_pending_callbacks) + callback(*this); +m_pending_callbacks.clear(); } return Status(); } diff --git a/lldb/unittests/Host/MainLoopTest.cpp b/lldb/unittests/Host/MainLoopTest.cpp index 890f6eb66197e..fc79c0e38a392 100644 --- a/lldb/unittests/Host/MainLoopTest.cpp +++ b/lldb/unittests/Host/MainLoopTest.cpp @@ -98,6 +98,56 @@ TEST_F(MainLoopTest, TerminatesImmediately) { ASSERT_EQ(1u, callback_count); } +TEST_F(MainLoopTest, PendingCallback) { + char X = 'X'; + size_t len = sizeof(X); + ASSERT_TRUE(socketpair[0]->Write(, len).Success()); + + MainLoop loop; + Status error; + auto handle = loop.RegisterReadObject( + socketpair[1], + [&](MainLoopBase ) { +// Both callbacks should be called before the loop terminates. +loop.AddPendingCallback(make_callback()); +loop.AddPendingCallback(make_callback()); +loop.RequestTermination(); + }, + error); + ASSERT_TRUE(error.Success()); + ASSERT_TRUE(handle); + ASSERT_TRUE(loop.Run().Success()); + ASSERT_EQ(2u, callback_count); +} + +TEST_F(MainLoopTest, PendingCallbackCalledOnlyOnce) { + char X = 'X'; + size_t len = sizeof(X); + ASSERT_TRUE(socketpair[0]->Write(, len).Success()); + + MainLoop loop; + Status error; + auto handle = loop.RegisterReadObject( + socketpair[1], + [&](MainLoopBase ) { +// Add one pending
[Lldb-commits] [lldb] bc04d24 - [lldb] [llgs] Implement non-stop style stop notification packets
Author: Michał Górny Date: 2022-06-21T19:04:20+02:00 New Revision: bc04d240850bab340341eaf3601c5ca996667319 URL: https://github.com/llvm/llvm-project/commit/bc04d240850bab340341eaf3601c5ca996667319 DIFF: https://github.com/llvm/llvm-project/commit/bc04d240850bab340341eaf3601c5ca996667319.diff LOG: [lldb] [llgs] Implement non-stop style stop notification packets Implement the support for %Stop asynchronous notification packet format in LLGS. This does not implement full support for non-stop mode for threaded programs -- process plugins continue stopping all threads on every event. However, it will be used to implement asynchronous events in multiprocess debugging. The non-stop protocol is enabled using QNonStop packet. When it is enabled, the server uses notification protocol instead of regular stop replies. Since all threads are always stopped, notifications are always generated for all active threads and copied into stop notification queue. If the queue was empty, the initial asynchronous %Stop notification is sent to the client immediately. The client needs to (eventually) acknowledge the notification by sending the vStopped packet, in which case it is popped from the queue and the stop reason for the next thread is reported. This continues until notification queue is empty again, in which case an OK reply is sent. Asychronous notifications are also used for vAttach results and program exits. The `?` packet uses a hybrid approach -- it returns the first stop reason synchronously, and exposes the stop reasons for remaining threads via vStopped queue. The change includes a test case for a program generating a segfault on 3 threads. The server is expected to generate a stop notification for the segfaulting thread, along with the notifications for the other running threads (with "no stop reason"). This verifies that the stop reasons are correctly reported for all threads, and that notification queue works. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D125575 Added: lldb/test/API/tools/lldb-server/TestNonStop.py Modified: lldb/include/lldb/Utility/StringExtractorGDBRemote.h lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h lldb/source/Utility/StringExtractorGDBRemote.cpp Removed: diff --git a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h index c1bf593c11dcb..2a63212e9d287 100644 --- a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h +++ b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h @@ -174,7 +174,10 @@ class StringExtractorGDBRemote : public StringExtractor { eServerPacketType_QMemTags, // write memory tags eServerPacketType_qLLDBSaveCore, -eServerPacketType_QSetIgnoredExceptions +eServerPacketType_QSetIgnoredExceptions, +eServerPacketType_QNonStop, +eServerPacketType_vStopped, +eServerPacketType_vCtrlC, }; ServerPacketType GetServerPacketType() const; diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py index cea963e456592..df1fd2cb71b6f 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py @@ -851,6 +851,7 @@ def add_qSupported_packets(self, client_features=[]): "memory-tagging", "qSaveCore", "native-signals", +"QNonStop", ] def parse_qSupported_response(self, context): diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py index 12dafd15283bc..d1d265d8852b5 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py @@ -866,7 +866,7 @@ def _handle_output_packet_string(packet_contents): class Server(object): -_GDB_REMOTE_PACKET_REGEX = re.compile(br'^\$([^\#]*)#[0-9a-fA-F]{2}') +_GDB_REMOTE_PACKET_REGEX = re.compile(br'^[\$%]([^\#]*)#[0-9a-fA-F]{2}') class ChecksumMismatch(Exception): pass diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index d660a4d070421..e5461c1899ec8 100644 ---
[Lldb-commits] [lldb] d3292c4 - [lldb] [test] Fix test_platform_file_fstat to account for negative ints
Author: Michał Górny Date: 2022-06-20T19:42:22+02:00 New Revision: d3292c4ba0ce13edb316d7fb63ccae376081a102 URL: https://github.com/llvm/llvm-project/commit/d3292c4ba0ce13edb316d7fb63ccae376081a102 DIFF: https://github.com/llvm/llvm-project/commit/d3292c4ba0ce13edb316d7fb63ccae376081a102.diff LOG: [lldb] [test] Fix test_platform_file_fstat to account for negative ints Fix test_platform_file_fstat to correctly truncate/max out the expected value when GDB Remote Serial Protocol specifies a value as an unsigned integer but the underlying platform type uses a signed integer. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128042 Added: Modified: lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py Removed: diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py b/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py index 57b2daf96143..fec1e95fa28c 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemotePlatformFile.py @@ -32,11 +32,11 @@ class GDBStat(typing.NamedTuple): def uint32_or_zero(x): -return x if x < 2**32 else 0 +return x if x < 2**32 and x >= 0 else 0 def uint32_or_max(x): -return x if x < 2**32 else 2**32 - 1 +return x if x < 2**32 and x >= 0 else 2**32 - 1 def uint32_trunc(x): ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 9407439 - [lldb] [test] Disable gmodules testing on FreeBSD
Author: Michał Górny Date: 2022-06-20T19:42:21+02:00 New Revision: 94074399ab0a2caefadc8fe4ecef70a938b396cc URL: https://github.com/llvm/llvm-project/commit/94074399ab0a2caefadc8fe4ecef70a938b396cc DIFF: https://github.com/llvm/llvm-project/commit/94074399ab0a2caefadc8fe4ecef70a938b396cc.diff LOG: [lldb] [test] Disable gmodules testing on FreeBSD The -gmodule tests currently fail on FreeBSD due to include bugs: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=264730 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128034 Added: Modified: lldb/packages/Python/lldbsuite/test/test_categories.py Removed: diff --git a/lldb/packages/Python/lldbsuite/test/test_categories.py b/lldb/packages/Python/lldbsuite/test/test_categories.py index 2fbf1a279042..a396741ccf8f 100644 --- a/lldb/packages/Python/lldbsuite/test/test_categories.py +++ b/lldb/packages/Python/lldbsuite/test/test_categories.py @@ -64,7 +64,7 @@ def is_supported_on_platform(category, platform, compiler_path): return platform in ["darwin", "macosx", "ios", "watchos", "tvos", "bridgeos"] elif category == "gmodules": # First, check to see if the platform can even support gmodules. -if platform not in ["freebsd", "darwin", "macosx", "ios", "watchos", "tvos", "bridgeos"]: +if platform not in ["darwin", "macosx", "ios", "watchos", "tvos", "bridgeos"]: return False return gmodules.is_compiler_clang_with_gmodules(compiler_path) return True ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] a36b9b3 - [lldb] [test] Make AVX/MPX register tests more robust and fix on BSD
Author: Michał Górny Date: 2022-06-20T19:42:21+02:00 New Revision: a36b9b382a03f70d6dfe46f0f1ca43d19ea6b6df URL: https://github.com/llvm/llvm-project/commit/a36b9b382a03f70d6dfe46f0f1ca43d19ea6b6df DIFF: https://github.com/llvm/llvm-project/commit/a36b9b382a03f70d6dfe46f0f1ca43d19ea6b6df.diff LOG: [lldb] [test] Make AVX/MPX register tests more robust and fix on BSD Make the AVX/MPX register tests more robust by checking for the presence of actual registers rather than register sets. Account for the option that the respective registers are defined but not available, as is the case on FreeBSD and NetBSD. This fixes test regression on these platforms. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D128041 Added: Modified: lldb/test/API/commands/register/register/register_command/TestRegisters.py Removed: diff --git a/lldb/test/API/commands/register/register/register_command/TestRegisters.py b/lldb/test/API/commands/register/register/register_command/TestRegisters.py index c3b26da3959d..5893acd92653 100644 --- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py +++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py @@ -393,31 +393,25 @@ def fp_register_write(self): st0regname + ' = 0']) -has_avx = False -has_mpx = False -# Returns an SBValueList. +# Check if AVX/MPX registers are defined at all. registerSets = currentFrame.GetRegisters() -for registerSet in registerSets: -set_name = registerSet.GetName().lower() -if 'advanced vector extensions' in set_name: -has_avx = True -# Darwin reports AVX registers as part of "Floating Point Registers" -elif self.platformIsDarwin() and 'floating point registers' in set_name: -has_avx = registerSet.GetChildMemberWithName('ymm0').IsValid() - -# FreeBSD/NetBSD reports missing register sets diff erently -# at the moment and triggers false positive here. -# TODO: remove FreeBSD/NetBSD exception when we make unsupported -# register groups correctly disappear. -if ('memory protection extension' in registerSet.GetName().lower() -and self.getPlatform() not in ["freebsd", "netbsd"]): -has_mpx = True +registers = frozenset(reg.GetName() for registerSet in registerSets + for reg in registerSet) +has_avx_regs = "ymm0" in registers +has_mpx_regs = "bnd0" in registers +# Check if they are actually present. +self.runCmd("register read -a") +output = self.res.GetOutput() +has_avx = "ymm0 =" in output +has_mpx = "bnd0 =" in output if has_avx: new_value = "{0x01 0x02 0x03 0x00 0x00 0x00 0x00 0x00 0x09 0x0a 0x2f 0x2f 0x2f 0x2f 0x0e 0x0f 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0c 0x0d 0x0e 0x0f}" self.write_and_read(currentFrame, "ymm0", new_value) self.write_and_read(currentFrame, "ymm7", new_value) self.expect("expr $ymm0", substrs=['vector_type']) +elif has_avx_regs: +self.expect("register read ymm0", substrs=["error: unavailable"]) else: self.expect("register read ymm0", substrs=["Invalid register name 'ymm0'"], error=True) @@ -434,6 +428,8 @@ def fp_register_write(self): new_value = "{0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08}" self.write_and_read(currentFrame, "bndstatus", new_value) self.expect("expr $bndstatus", substrs = ['vector_type']) +elif has_mpx_regs: +self.expect("register read bnd0", substrs=["error: unavailable"]) else: self.expect("register read bnd0", substrs=["Invalid register name 'bnd0'"], error=True) ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] af93f12 - [lldb] [llgs] Refactor SendStopReplyPacketForThread for multiprocess
Author: Michał Górny Date: 2022-06-20T19:42:21+02:00 New Revision: af93f123b92eb3591d0667c24db9cd325d670912 URL: https://github.com/llvm/llvm-project/commit/af93f123b92eb3591d0667c24db9cd325d670912 DIFF: https://github.com/llvm/llvm-project/commit/af93f123b92eb3591d0667c24db9cd325d670912.diff LOG: [lldb] [llgs] Refactor SendStopReplyPacketForThread for multiprocess Refactor SendStopReplyPacketForThread() to accept process instance as a parameter rather than use m_current_process. This future-proofs it for multiprocess support. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127289 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index e173f04bebe4..5e54be331553 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -768,19 +768,13 @@ GetJSONThreadsInfo(NativeProcessProtocol , bool abridged) { GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( -lldb::tid_t tid) { +NativeProcessProtocol , lldb::tid_t tid) { Log *log = GetLog(LLDBLog::Process | LLDBLog::Thread); - // Ensure we have a debugged process. - if (!m_current_process || - (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID)) -return SendErrorResponse(50); - - LLDB_LOG(log, "preparing packet for pid {0} tid {1}", - m_current_process->GetID(), tid); + LLDB_LOG(log, "preparing packet for pid {0} tid {1}", process.GetID(), tid); // Ensure we can get info on the given thread. - NativeThreadProtocol *thread = m_current_process->GetThreadByID(tid); + NativeThreadProtocol *thread = process.GetThreadByID(tid); if (!thread) return SendErrorResponse(51); @@ -803,7 +797,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( LLDB_LOG( log, "pid {0}, tid {1}, got signal signo = {2}, reason = {3}, exc_type = {4}", - m_current_process->GetID(), tid, signum, int(tid_stop_info.reason), + process.GetID(), tid, signum, int(tid_stop_info.reason), tid_stop_info.details.exception.type); // Print the signal number. @@ -813,7 +807,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( response.PutCString("thread:"); if (bool(m_extensions_supported & NativeProcessProtocol::Extension::multiprocess)) -response.Format("p{0:x-}.", m_current_process->GetID()); +response.Format("p{0:x-}.", process.GetID()); response.Format("{0:x-};", tid); // Include the thread name if there is one. @@ -845,9 +839,9 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( uint32_t thread_index = 0; NativeThreadProtocol *listed_thread; -for (listed_thread = m_current_process->GetThreadAtIndex(thread_index); - listed_thread; ++thread_index, -listed_thread = m_current_process->GetThreadAtIndex(thread_index)) { +for (listed_thread = process.GetThreadAtIndex(thread_index); listed_thread; + ++thread_index, +listed_thread = process.GetThreadAtIndex(thread_index)) { if (thread_index > 0) response.PutChar(','); response.Printf("%" PRIx64, listed_thread->GetID()); @@ -872,7 +866,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( } else { LLDB_LOG_ERROR(log, threads_info.takeError(), "failed to prepare a jstopinfo field for pid {1}: {0}", - m_current_process->GetID()); + process.GetID()); } } @@ -880,7 +874,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( response.PutCString("thread-pcs"); char delimiter = ':'; for (NativeThreadProtocol *thread; - (thread = m_current_process->GetThreadAtIndex(i)) != nullptr; ++i) { + (thread = process.GetThreadAtIndex(i)) != nullptr; ++i) { NativeRegisterContext& reg_ctx = thread->GetRegisterContext(); uint32_t reg_to_read = reg_ctx.ConvertRegisterKindToRegisterNumber( @@ -1718,7 +1712,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReasonForState( // Make sure we set the current thread so g and p packets return the data // the gdb will expect. SetCurrentThreadID(tid); -return SendStopReplyPacketForThread(tid); +return SendStopReplyPacketForThread(*m_current_process, tid); } case eStateInvalid: @@ -3331,6 +3325,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qThreadStopInfo( StringExtractorGDBRemote ) {
[Lldb-commits] [lldb] f8c6de8 - [lldb] [llgs] Refactor SendStopReasonForState for multiprocess
Author: Michał Górny Date: 2022-06-20T19:42:21+02:00 New Revision: f8c6de8dbbd7ee0d037e07a94e3c5a370c2edaff URL: https://github.com/llvm/llvm-project/commit/f8c6de8dbbd7ee0d037e07a94e3c5a370c2edaff DIFF: https://github.com/llvm/llvm-project/commit/f8c6de8dbbd7ee0d037e07a94e3c5a370c2edaff.diff LOG: [lldb] [llgs] Refactor SendStopReasonForState for multiprocess Refactor GDBRemoteCommunicationServerLLGS::SendStopReasonForState() to accept process as an argument rather than hardcoding m_current_process, in order to make it work correctly for multiprocess scenarios. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127497 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 5e54be331553..6fffef8b1eca 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -983,7 +983,8 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited( Log *log = GetLog(LLDBLog::Process); LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__); - PacketResult result = SendStopReasonForState(StateType::eStateExited); + PacketResult result = + SendStopReasonForState(*process, StateType::eStateExited); if (result != PacketResult::Success) { LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s failed to send stop " @@ -1015,7 +1016,8 @@ void GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped( break; default: // In all other cases, send the stop reason. -PacketResult result = SendStopReasonForState(StateType::eStateStopped); +PacketResult result = +SendStopReasonForState(*process, StateType::eStateStopped); if (result != PacketResult::Success) { LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s failed to send stop " @@ -1686,12 +1688,13 @@ GDBRemoteCommunicationServerLLGS::Handle_stop_reason( if (!m_current_process) return SendErrorResponse(02); - return SendStopReasonForState(m_current_process->GetState()); + return SendStopReasonForState(*m_current_process, +m_current_process->GetState()); } GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerLLGS::SendStopReasonForState( -lldb::StateType process_state) { +NativeProcessProtocol , lldb::StateType process_state) { Log *log = GetLog(LLDBLog::Process); switch (process_state) { @@ -1707,22 +1710,21 @@ GDBRemoteCommunicationServerLLGS::SendStopReasonForState( case eStateSuspended: case eStateStopped: case eStateCrashed: { -assert(m_current_process != nullptr); -lldb::tid_t tid = m_current_process->GetCurrentThreadID(); +lldb::tid_t tid = process.GetCurrentThreadID(); // Make sure we set the current thread so g and p packets return the data // the gdb will expect. SetCurrentThreadID(tid); -return SendStopReplyPacketForThread(*m_current_process, tid); +return SendStopReplyPacketForThread(process, tid); } case eStateInvalid: case eStateUnloaded: case eStateExited: -return SendWResponse(m_current_process); +return SendWResponse(); default: LLDB_LOG(log, "pid {0}, current state reporting not handled: {1}", - m_current_process->GetID(), process_state); + process.GetID(), process_state); break; } @@ -3172,7 +3174,9 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttach( } // Notify we attached by sending a stop packet. - return SendStopReasonForState(m_current_process->GetState()); + assert(m_current_process); + return SendStopReasonForState(*m_current_process, +m_current_process->GetState()); } GDBRemoteCommunication::PacketResult @@ -3202,7 +3206,9 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttachWait( } // Notify we attached by sending a stop packet. - return SendStopReasonForState(m_current_process->GetState()); + assert(m_current_process); + return SendStopReasonForState(*m_current_process, +m_current_process->GetState()); } GDBRemoteCommunication::PacketResult @@ -3238,7 +3244,9 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttachOrWait( } // Notify we attached by sending a stop packet. - return SendStopReasonForState(m_current_process->GetState()); + assert(m_current_process); + return SendStopReasonForState(*m_current_process, +m_current_process->GetState()); }
[Lldb-commits] [lldb] e4d6ed5 - [lldb] [llgs] Include process id in W/X stop reasons
Author: Michał Górny Date: 2022-06-20T13:37:23+02:00 New Revision: e4d6ed58a86edc339ae124b74668b600f2a0f6d5 URL: https://github.com/llvm/llvm-project/commit/e4d6ed58a86edc339ae124b74668b600f2a0f6d5 DIFF: https://github.com/llvm/llvm-project/commit/e4d6ed58a86edc339ae124b74668b600f2a0f6d5.diff LOG: [lldb] [llgs] Include process id in W/X stop reasons Include the process identifier in W/X stop reasons when multiprocess extensions are enabled. The LLDB client does not support process identifiers there at the moment but it parses packets in such a way that their presence does not cause any problems. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127191 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 0a44929ce2b7b..2b491f505aca1 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -474,6 +474,8 @@ GDBRemoteCommunicationServerLLGS::SendWResponse( StreamGDBRemote response; response.Format("{0:g}", *wait_status); + if (bool(m_extensions_supported & NativeProcessProtocol::Extension::multiprocess)) +response.Format(";process:{0:x-}", process->GetID()); return SendPacketNoLock(response.GetString()); } diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 3ce10f5964b8e..45f3c95809da0 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -74,7 +74,7 @@ def test_fork(self): # resume the parent self.test_sequence.add_log_lines([ "read packet: $c#00", -{"direction": "send", "regex": r"[$]W00#.*"}, +{"direction": "send", "regex": r"[$]W00;process:[0-9a-f]+#.*"}, ], True) self.expect_gdbremote_sequence() @@ -87,7 +87,7 @@ def test_vfork(self): "read packet: $c#00", {"direction": "send", "regex": r"[$]T.*vforkdone.*"}, "read packet: $c#00", -{"direction": "send", "regex": r"[$]W00#.*"}, +{"direction": "send", "regex": r"[$]W00;process:[0-9a-f]+#.*"}, ], True) self.expect_gdbremote_sequence() @@ -135,7 +135,7 @@ def fork_and_follow_test(self, variant): # resume the child self.test_sequence.add_log_lines([ "read packet: $c#00", -{"direction": "send", "regex": r"[$]W00#.*"}, +{"direction": "send", "regex": r"[$]W00;process:[0-9a-f]+#.*"}, ], True) self.expect_gdbremote_sequence() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] ac570fb - [lldb] [llgs] Include process ID in stop responses
Author: Michał Górny Date: 2022-06-20T13:37:23+02:00 New Revision: ac570fbb8521a31a1931cc070e1b259fcac6a30f URL: https://github.com/llvm/llvm-project/commit/ac570fbb8521a31a1931cc070e1b259fcac6a30f DIFF: https://github.com/llvm/llvm-project/commit/ac570fbb8521a31a1931cc070e1b259fcac6a30f.diff LOG: [lldb] [llgs] Include process ID in stop responses Include the process identifier in the `T` stop responses when multiprocess extension is enabled (i.e. prepend it to the thread identifier). Use the exposed identifier to simplify the fork-and-follow tests. The LLDB client accounts for the possible PID since the multiprocess extension support was added in b601c6719226fb83c43dae62a581e5ee08bfb169. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127192 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py Removed: diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 2b491f505aca..e173f04bebe4 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -809,8 +809,12 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread( // Print the signal number. response.PutHex8(signum & 0xff); - // Include the tid. - response.Printf("thread:%" PRIx64 ";", tid); + // Include the (pid and) tid. + response.PutCString("thread:"); + if (bool(m_extensions_supported & + NativeProcessProtocol::Extension::multiprocess)) +response.Format("p{0:x-}.", m_current_process->GetID()); + response.Format("{0:x-};", tid); // Include the thread name if there is one. const std::string thread_name = thread->GetName(); diff --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py index 45f3c95809da..2156180e7423 100644 --- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py +++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py @@ -101,15 +101,12 @@ def fork_and_follow_test(self, variant): self.reset_test_sequence() # continue and expect fork -procinfo_regex = "[$]pid:([0-9a-f]+);.*" -fork_regex = "[$]T.*;{}:p([0-9a-f]+)[.]([0-9a-f]+).*".format(variant) +fork_regex = ("[$]T[0-9a-f]{{2}}thread:p([0-9a-f]+)[.][0-9a-f]+;.*" + "{}:p([0-9a-f]+)[.]([0-9a-f]+).*".format(variant)) self.test_sequence.add_log_lines([ -"read packet: $qProcessInfo#00", -{"direction": "send", "regex": procinfo_regex, - "capture": {1: "parent_pid"}}, "read packet: $c#00", {"direction": "send", "regex": fork_regex, - "capture": {1: "pid", 2: "tid"}}, + "capture": {1: "parent_pid", 2: "pid", 3: "tid"}}, ], True) ret = self.expect_gdbremote_sequence() parent_pid, pid, tid = (int(ret[x], 16) for x ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits