[Lldb-commits] [lldb] [lldb][AIX] Added PlatformAIX plugin (PR #121273)
https://github.com/DavidSpickett commented: I'm not clear what you're asking for feedback on here. Starting with a copy of the Linux platform, I understand that. However the final changes don't look that different so I assume you have: * Copied the Linux platform. * Updated it until it builds on AIX. * And now want some feedback for the next part? If so, I think the first thing to do is work out if any of these Linux constructs apply to AIX at all. For example does uname exist and work? Does the siginfo type match up (certainly the MIPS code is not needed for AIX)? Then we'll be down to what you actually want to keep for AIX, and from there we can think about whether it's worth sharing any of it. My guess is that a lot of this won't apply to AIX or be different enough to warrant it being its own copy of the code. For example we already have different versions of GetSigInfoType for NetBSD/FreeBSD. https://github.com/llvm/llvm-project/pull/121273 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] [LLDB][Process] Add LSX and LASX register definitions and operations on the LoongArch64 (PR #120664)
https://github.com/DavidSpickett commented: I should have said this before you wrote out all these tests, so apologies for this up front, but - There's no reason these tests need to be native, host only, tests. Cross compiling them is not a problem. So I'd like to see these as API tests instead, using Python. The nice thing about that is you can merge a lot of it into one file. I think it makes sense to add a LoongArch folder next to the AArch64 one in test/API/linux, and write a test like: https://github.com/llvm/llvm-project/tree/main/lldb/test/API/linux/aarch64/tls_registers You can then have one program file with functions to write in each of the ways you need. You will have to pass some argument to the program to tell it what to do, as calling these functions via expressions will not change anything because lldb will ("helpfully" :) ) restore these registers afterwards. You can also set breakpoints wherever you want, without having to manually skip breakpoints already in the code. You can add something like `isAArch64SME` to look for the CPU features you need in /proc/cpuinfo, same thing for skipping if it's not LoongArch. The program code and the values you check for are fine as is, the setup just needs to be a bit more flexible. https://github.com/llvm/llvm-project/pull/120664 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] [LLDB][Process] Add LSX and LASX register definitions and operations on the LoongArch64 (PR #120664)
DavidSpickett wrote: Making the tests remote compatible also makes the changes to lit cpu id unnecessary. https://github.com/llvm/llvm-project/pull/120664 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Linux] Mark memory regions used for shadow stacks (PR #117861)
DavidSpickett wrote: ping! https://github.com/llvm/llvm-project/pull/117861 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add a return opcode to the formatter bytecode (PR #121602)
https://github.com/kastiglione approved this pull request. https://github.com/llvm/llvm-project/pull/121602 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] ee1adc5 - [lldb] Add a return opcode to the formatter bytecode (#121602)
Author: Adrian Prantl Date: 2025-01-03T15:26:40-08:00 New Revision: ee1adc5aab4fb517314358ce03cfda426da9c4ce URL: https://github.com/llvm/llvm-project/commit/ee1adc5aab4fb517314358ce03cfda426da9c4ce DIFF: https://github.com/llvm/llvm-project/commit/ee1adc5aab4fb517314358ce03cfda426da9c4ce.diff LOG: [lldb] Add a return opcode to the formatter bytecode (#121602) In LLVM we love our early exists and this opcode allows for simpler code generation. Added: Modified: lldb/docs/resources/formatterbytecode.rst lldb/examples/python/formatter_bytecode.py lldb/source/DataFormatters/FormatterBytecode.cpp lldb/source/DataFormatters/FormatterBytecode.def lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp Removed: diff --git a/lldb/docs/resources/formatterbytecode.rst b/lldb/docs/resources/formatterbytecode.rst index 20e148363ef957..34fb0f7ee924c4 100644 --- a/lldb/docs/resources/formatterbytecode.rst +++ b/lldb/docs/resources/formatterbytecode.rst @@ -75,6 +75,7 @@ These manipulate the control stack and program counter. Both `if` and `ifelse` e 0x12 `ifelse``(UInt -> )` pop two blocks from the control stack, if the top of the data stack is nonzero, execute the first, otherwise the second. + 0x13 `return`pop the entire control stack and return == Literals for basic types diff --git a/lldb/examples/python/formatter_bytecode.py b/lldb/examples/python/formatter_bytecode.py index ccd0c68a75483c..36a14be283f319 100644 --- a/lldb/examples/python/formatter_bytecode.py +++ b/lldb/examples/python/formatter_bytecode.py @@ -35,6 +35,7 @@ def define_opcode(n, mnemonic, name): define_opcode(0x10, "{", "begin") define_opcode(0x11, "if", "if") define_opcode(0x12, "ifelse", "ifelse") +define_opcode(0x13, "return", "return") define_opcode(0x20, None, "lit_uint") define_opcode(0x21, None, "lit_int") @@ -342,6 +343,9 @@ def next_byte(): else: frame.append(control.pop()) control.pop() +elif b == op_return: +control.clear() +return data[-1] # Literals. elif b == op_lit_uint: diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp b/lldb/source/DataFormatters/FormatterBytecode.cpp index e49c7506781875..7f3dbe0dba37d6 100644 --- a/lldb/source/DataFormatters/FormatterBytecode.cpp +++ b/lldb/source/DataFormatters/FormatterBytecode.cpp @@ -304,6 +304,9 @@ llvm::Error Interpret(std::vector &control, control.pop_back(); activate_block(); continue; +case op_return: + control.clear(); + return pc.takeError(); // Literals. case op_lit_uint: diff --git a/lldb/source/DataFormatters/FormatterBytecode.def b/lldb/source/DataFormatters/FormatterBytecode.def index c6645631fa0065..29e0bee541c73c 100644 --- a/lldb/source/DataFormatters/FormatterBytecode.def +++ b/lldb/source/DataFormatters/FormatterBytecode.def @@ -27,6 +27,7 @@ DEFINE_OPCODE(0x06, "rot", rot) DEFINE_OPCODE(0x10, "{", begin) DEFINE_OPCODE(0x11, "if", if) DEFINE_OPCODE(0x12, "ifelse", ifelse) +DEFINE_OPCODE(0x13, "return", return) DEFINE_OPCODE(0x20, nullptr, lit_uint) DEFINE_OPCODE(0x21, nullptr, lit_int) diff --git a/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp b/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp index 7307db650c1629..5e980c3e1913cf 100644 --- a/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp +++ b/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp @@ -97,6 +97,16 @@ TEST_F(FormatterBytecodeTest, ControlOps) { data)); ASSERT_EQ(data.Pop(), 42u); } + { +DataStack data; +ASSERT_TRUE(Interpret({op_lit_uint, 1, op_begin, 3, op_lit_uint, 42, + op_return, op_if, op_lit_uint, 23}, + data)); +ASSERT_EQ(data.Pop(), 42u); + } +} + +TEST_F(FormatterBytecodeTest, ConversionOps) { { DataStack data(lldb::ValueObjectSP{}); ASSERT_TRUE(Interpret({op_is_null}, data)); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix bad method call in `TestExprDiagnostics.py` (PR #120901)
adrian-prantl wrote: Thanks for fixing this! https://github.com/llvm/llvm-project/pull/120901 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Proof of concept data formatter compiler for Python (PR #113734)
https://github.com/kastiglione updated https://github.com/llvm/llvm-project/pull/113734 >From 57223942e91c47d0a61b148a65247cd9cbb16496 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Fri, 25 Oct 2024 12:56:00 -0700 Subject: [PATCH 1/2] [lldb] Proof of concept data formatter compiler for Python --- .../formatter-bytecode/optional_summary.py| 14 ++ .../formatter-bytecode/python_to_assembly.py | 145 ++ 2 files changed, 159 insertions(+) create mode 100644 lldb/examples/formatter-bytecode/optional_summary.py create mode 100755 lldb/examples/formatter-bytecode/python_to_assembly.py diff --git a/lldb/examples/formatter-bytecode/optional_summary.py b/lldb/examples/formatter-bytecode/optional_summary.py new file mode 100644 index 00..68e672d86613d1 --- /dev/null +++ b/lldb/examples/formatter-bytecode/optional_summary.py @@ -0,0 +1,14 @@ +def OptionalSummaryProvider(valobj, _): +failure = 2 +storage = valobj.GetChildMemberWithName("Storage") +hasVal = storage.GetChildMemberWithName("hasVal").GetValueAsUnsigned(failure) +if hasVal == failure: +return "" + +if hasVal == 0: +return "None" + +underlying_type = storage.GetType().GetTemplateArgumentType(0) +value = storage.GetChildMemberWithName("value") +value = value.Cast(underlying_type) +return value.GetSummary() diff --git a/lldb/examples/formatter-bytecode/python_to_assembly.py b/lldb/examples/formatter-bytecode/python_to_assembly.py new file mode 100755 index 00..6e2adbe093fdac --- /dev/null +++ b/lldb/examples/formatter-bytecode/python_to_assembly.py @@ -0,0 +1,145 @@ +#!/usr/bin/python3 + +import ast +import io +import sys +from typing import Any + +BUILTINS = { +"Cast": "@cast", +"GetChildMemberWithName": "@get_child_with_name", +"GetSummary": "@get_summary", +"GetTemplateArgumentType": "@get_template_argument_type", +"GetType": "@get_type", +"GetValueAsUnsigned": "@get_value_as_unsigned", +} + +COMPS = { +ast.Eq: "=", +ast.NotEq: "!=", +ast.Lt: "<", +ast.LtE: "=<", +ast.Gt: ">", +ast.GtE: "=>", +} + +class Compiler(ast.NodeVisitor): +# Track the stack index of locals variables. +# +# This is essentially an ordered dictionary, where the key is an index on +# the stack, and the value is the name of the variable whose value is at +# that index. +# +# Ex: `locals[0]` is the name of the first value pushed on the stack, etc. +locals: list[str] + +buffer: io.StringIO +final_buffer: io.StringIO + +def __init__(self) -> None: +self.locals = [] +self.buffer = io.StringIO() +self.final_buffer = io.StringIO() + +def visit_FunctionDef(self, node: ast.FunctionDef) -> None: +# Initialize `locals` with the (positional) arguments. +self.locals = [arg.arg for arg in node.args.args] +self.generic_visit(node) +self.locals.clear() + +def visit_Compare(self, node: ast.Compare) -> None: +self.visit(node.left) +# XXX: Does not handle multiple comparisons, ex: `0 < x < 10` +self.visit(node.comparators[0]) +self._output(COMPS[type(node.ops[0])]) + +def visit_If(self, node: ast.If) -> None: +self.visit(node.test) + +# Does the body `return`? +has_return = any(isinstance(x, ast.Return) for x in node.body) + +self._output("{") +self._visit_each(node.body) +if not node.orelse and not has_return: +# No else, and no early exit: a simple `if` +self._output("} if") +return + +self._output("}") +if node.orelse: +# Handle else. +self._output("{") +self._visit_each(node.orelse) +self._output("} ifelse") +elif has_return: +# Convert early exit into an `ifelse`. +self._output("{") +self._output("} ifelse", final=True) + +def visit_Constant(self, node: ast.Constant) -> None: +if isinstance(node.value, str): +self._output(f'"{node.value}"') +elif isinstance(node.value, bool): +self._output(int(node.value)) +else: +self._output(node.value) + +def visit_Call(self, node: ast.Call) -> None: +if isinstance(node.func, ast.Attribute): +# The receiver is the left hande side of the dot. +receiver = node.func.value +method = node.func.attr +if selector := BUILTINS.get(method): +# Visit the method's receiver to have its value on the stack. +self.visit(receiver) +# Visit the args to position them on the stack. +self._visit_each(node.args) +self._output(f"{selector} call") +else: +# TODO: fail +print(f"error: unsupported method {node.func.attr}", file=sys.stderr) + +def visit_Ass
[Lldb-commits] [lldb] [lldb] Add a return opcode to the formatter bytecode (PR #121602)
https://github.com/adrian-prantl closed https://github.com/llvm/llvm-project/pull/121602 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add a return opcode to the formatter bytecode (PR #121602)
https://github.com/adrian-prantl created https://github.com/llvm/llvm-project/pull/121602 In LLVM we love our early exists and this opcode allows for simpler code generation. >From bffb3f827b2e2918cd6858728efbfefd319ae2dc Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 3 Jan 2025 12:51:15 -0800 Subject: [PATCH] [lldb] Add a return opcode to the formatter bytecode In LLVM we love our early exists and this opcode allows for simpler code generation. --- lldb/docs/resources/formatterbytecode.rst | 1 + lldb/examples/python/formatter_bytecode.py | 4 lldb/source/DataFormatters/FormatterBytecode.cpp | 3 +++ lldb/source/DataFormatters/FormatterBytecode.def | 1 + lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp | 10 ++ 5 files changed, 19 insertions(+) diff --git a/lldb/docs/resources/formatterbytecode.rst b/lldb/docs/resources/formatterbytecode.rst index 20e148363ef957..34fb0f7ee924c4 100644 --- a/lldb/docs/resources/formatterbytecode.rst +++ b/lldb/docs/resources/formatterbytecode.rst @@ -75,6 +75,7 @@ These manipulate the control stack and program counter. Both `if` and `ifelse` e 0x12 `ifelse``(UInt -> )` pop two blocks from the control stack, if the top of the data stack is nonzero, execute the first, otherwise the second. + 0x13 `return`pop the entire control stack and return == Literals for basic types diff --git a/lldb/examples/python/formatter_bytecode.py b/lldb/examples/python/formatter_bytecode.py index ccd0c68a75483c..36a14be283f319 100644 --- a/lldb/examples/python/formatter_bytecode.py +++ b/lldb/examples/python/formatter_bytecode.py @@ -35,6 +35,7 @@ def define_opcode(n, mnemonic, name): define_opcode(0x10, "{", "begin") define_opcode(0x11, "if", "if") define_opcode(0x12, "ifelse", "ifelse") +define_opcode(0x13, "return", "return") define_opcode(0x20, None, "lit_uint") define_opcode(0x21, None, "lit_int") @@ -342,6 +343,9 @@ def next_byte(): else: frame.append(control.pop()) control.pop() +elif b == op_return: +control.clear() +return data[-1] # Literals. elif b == op_lit_uint: diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp b/lldb/source/DataFormatters/FormatterBytecode.cpp index e49c7506781875..7f3dbe0dba37d6 100644 --- a/lldb/source/DataFormatters/FormatterBytecode.cpp +++ b/lldb/source/DataFormatters/FormatterBytecode.cpp @@ -304,6 +304,9 @@ llvm::Error Interpret(std::vector &control, control.pop_back(); activate_block(); continue; +case op_return: + control.clear(); + return pc.takeError(); // Literals. case op_lit_uint: diff --git a/lldb/source/DataFormatters/FormatterBytecode.def b/lldb/source/DataFormatters/FormatterBytecode.def index c6645631fa0065..29e0bee541c73c 100644 --- a/lldb/source/DataFormatters/FormatterBytecode.def +++ b/lldb/source/DataFormatters/FormatterBytecode.def @@ -27,6 +27,7 @@ DEFINE_OPCODE(0x06, "rot", rot) DEFINE_OPCODE(0x10, "{", begin) DEFINE_OPCODE(0x11, "if", if) DEFINE_OPCODE(0x12, "ifelse", ifelse) +DEFINE_OPCODE(0x13, "return", return) DEFINE_OPCODE(0x20, nullptr, lit_uint) DEFINE_OPCODE(0x21, nullptr, lit_int) diff --git a/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp b/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp index 7307db650c1629..5e980c3e1913cf 100644 --- a/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp +++ b/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp @@ -97,6 +97,16 @@ TEST_F(FormatterBytecodeTest, ControlOps) { data)); ASSERT_EQ(data.Pop(), 42u); } + { +DataStack data; +ASSERT_TRUE(Interpret({op_lit_uint, 1, op_begin, 3, op_lit_uint, 42, + op_return, op_if, op_lit_uint, 23}, + data)); +ASSERT_EQ(data.Pop(), 42u); + } +} + +TEST_F(FormatterBytecodeTest, ConversionOps) { { DataStack data(lldb::ValueObjectSP{}); ASSERT_TRUE(Interpret({op_is_null}, data)); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add a return opcode to the formatter bytecode (PR #121602)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Adrian Prantl (adrian-prantl) Changes In LLVM we love our early exists and this opcode allows for simpler code generation. --- Full diff: https://github.com/llvm/llvm-project/pull/121602.diff 5 Files Affected: - (modified) lldb/docs/resources/formatterbytecode.rst (+1) - (modified) lldb/examples/python/formatter_bytecode.py (+4) - (modified) lldb/source/DataFormatters/FormatterBytecode.cpp (+3) - (modified) lldb/source/DataFormatters/FormatterBytecode.def (+1) - (modified) lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp (+10) ``diff diff --git a/lldb/docs/resources/formatterbytecode.rst b/lldb/docs/resources/formatterbytecode.rst index 20e148363ef957..34fb0f7ee924c4 100644 --- a/lldb/docs/resources/formatterbytecode.rst +++ b/lldb/docs/resources/formatterbytecode.rst @@ -75,6 +75,7 @@ These manipulate the control stack and program counter. Both `if` and `ifelse` e 0x12 `ifelse``(UInt -> )` pop two blocks from the control stack, if the top of the data stack is nonzero, execute the first, otherwise the second. + 0x13 `return`pop the entire control stack and return == Literals for basic types diff --git a/lldb/examples/python/formatter_bytecode.py b/lldb/examples/python/formatter_bytecode.py index ccd0c68a75483c..36a14be283f319 100644 --- a/lldb/examples/python/formatter_bytecode.py +++ b/lldb/examples/python/formatter_bytecode.py @@ -35,6 +35,7 @@ def define_opcode(n, mnemonic, name): define_opcode(0x10, "{", "begin") define_opcode(0x11, "if", "if") define_opcode(0x12, "ifelse", "ifelse") +define_opcode(0x13, "return", "return") define_opcode(0x20, None, "lit_uint") define_opcode(0x21, None, "lit_int") @@ -342,6 +343,9 @@ def next_byte(): else: frame.append(control.pop()) control.pop() +elif b == op_return: +control.clear() +return data[-1] # Literals. elif b == op_lit_uint: diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp b/lldb/source/DataFormatters/FormatterBytecode.cpp index e49c7506781875..7f3dbe0dba37d6 100644 --- a/lldb/source/DataFormatters/FormatterBytecode.cpp +++ b/lldb/source/DataFormatters/FormatterBytecode.cpp @@ -304,6 +304,9 @@ llvm::Error Interpret(std::vector &control, control.pop_back(); activate_block(); continue; +case op_return: + control.clear(); + return pc.takeError(); // Literals. case op_lit_uint: diff --git a/lldb/source/DataFormatters/FormatterBytecode.def b/lldb/source/DataFormatters/FormatterBytecode.def index c6645631fa0065..29e0bee541c73c 100644 --- a/lldb/source/DataFormatters/FormatterBytecode.def +++ b/lldb/source/DataFormatters/FormatterBytecode.def @@ -27,6 +27,7 @@ DEFINE_OPCODE(0x06, "rot", rot) DEFINE_OPCODE(0x10, "{", begin) DEFINE_OPCODE(0x11, "if", if) DEFINE_OPCODE(0x12, "ifelse", ifelse) +DEFINE_OPCODE(0x13, "return", return) DEFINE_OPCODE(0x20, nullptr, lit_uint) DEFINE_OPCODE(0x21, nullptr, lit_int) diff --git a/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp b/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp index 7307db650c1629..5e980c3e1913cf 100644 --- a/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp +++ b/lldb/unittests/DataFormatter/FormatterBytecodeTest.cpp @@ -97,6 +97,16 @@ TEST_F(FormatterBytecodeTest, ControlOps) { data)); ASSERT_EQ(data.Pop(), 42u); } + { +DataStack data; +ASSERT_TRUE(Interpret({op_lit_uint, 1, op_begin, 3, op_lit_uint, 42, + op_return, op_if, op_lit_uint, 23}, + data)); +ASSERT_EQ(data.Pop(), 42u); + } +} + +TEST_F(FormatterBytecodeTest, ConversionOps) { { DataStack data(lldb::ValueObjectSP{}); ASSERT_TRUE(Interpret({op_is_null}, data)); `` https://github.com/llvm/llvm-project/pull/121602 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add a return opcode to the formatter bytecode (PR #121602)
kastiglione wrote: Nested conditionals is where this will be helpful: Consider this python: ```python if first == 1: if second == 2: return "thing" return "other" ``` without a `return` op, the above code would have to be transformed to: ```python if first == 1: if second == 2: result = "thing" if not (first == 1 and second == 2): result = "other" ``` the bytecode for this this would look something like: ``` pick … # get `first` from the stack dup 1 == { pick … # get `second` from the stack dup 2 == { "thing" } if } if & ~ # not (first == 1 and second == 2) { "other" } if ``` with a `return` op, it simplifies to: ``` pick … # get `first` from the stack 1 == { pick … # get `second` from the stack 2 == { "thing" return } if } if "other" ``` https://github.com/llvm/llvm-project/pull/121602 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] Revert "[LLDB] Add a target.launch-working-dir setting" (PR #114973)
DavidSpickett wrote: https://github.com/llvm/llvm-project/commit/e952728f88c8b0e0208dc991dd9a04fe8c211cfb relanded this. https://github.com/llvm/llvm-project/pull/114973 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
@@ -0,0 +1,154 @@ +//===-- HostInfoAIX.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Host/aix/HostInfoAIX.h" +#include "lldb/Host/Config.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +#include "llvm/Support/Threading.h" + +#include +#include +#include +#include +#include + +#include +#include + +using namespace lldb_private; + +namespace { +struct HostInfoAIXFields { + llvm::once_flag m_distribution_once_flag; + std::string m_distribution_id; +}; +} // namespace + +static HostInfoAIXFields *g_fields = nullptr; + +void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) { + HostInfoPosix::Initialize(helper); + + g_fields = new HostInfoAIXFields(); +} + +void HostInfoAIX::Terminate() { + assert(g_fields && "Missing call to Initialize?"); + delete g_fields; + g_fields = nullptr; + HostInfoBase::Terminate(); +} + +llvm::StringRef HostInfoAIX::GetDistributionId() { DavidSpickett wrote: What would a distribution mean in the context of AIX? MacOS for example doesn't return anything for this, I presume because every Mac OS is just Apple's Mac OS. Whereas a Linux can come from many vendors. So if IBM is the only AIX vendor then this function can be deleted. ``` /// Returns the distribution id of the host /// /// This will be something like "ubuntu", "fedora", etc. on Linux. /// /// \return Returns either std::nullopt or a reference to a const std::string /// containing the distribution id static llvm::StringRef GetDistributionId() { return llvm::StringRef(); } ``` In any case, I don't think it's too important. Probably shown to the user at some point but nothing seems to make decisions from it. https://github.com/llvm/llvm-project/pull/117906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
@@ -0,0 +1,154 @@ +//===-- HostInfoAIX.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Host/aix/HostInfoAIX.h" +#include "lldb/Host/Config.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +#include "llvm/Support/Threading.h" + +#include +#include +#include +#include +#include + +#include +#include + +using namespace lldb_private; + +namespace { +struct HostInfoAIXFields { + llvm::once_flag m_distribution_once_flag; + std::string m_distribution_id; +}; +} // namespace + +static HostInfoAIXFields *g_fields = nullptr; + +void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) { + HostInfoPosix::Initialize(helper); + + g_fields = new HostInfoAIXFields(); +} + +void HostInfoAIX::Terminate() { + assert(g_fields && "Missing call to Initialize?"); + delete g_fields; + g_fields = nullptr; + HostInfoBase::Terminate(); +} + +llvm::StringRef HostInfoAIX::GetDistributionId() { + assert(g_fields && "Missing call to Initialize?"); + // Try to run 'lbs_release -i', and use that response for the distribution + // id. + llvm::call_once(g_fields->m_distribution_once_flag, []() { +Log *log = GetLog(LLDBLog::Host); +LLDB_LOGF(log, "attempting to determine AIX distribution..."); + +// check if the lsb_release command exists at one of the following paths +const char *const exe_paths[] = {"/bin/lsb_release", + "/usr/bin/lsb_release"}; + +for (size_t exe_index = 0; + exe_index < sizeof(exe_paths) / sizeof(exe_paths[0]); ++exe_index) { + const char *const get_distribution_info_exe = exe_paths[exe_index]; + if (access(get_distribution_info_exe, F_OK)) { +// this exe doesn't exist, move on to next exe +LLDB_LOGF(log, "executable doesn't exist: %s", + get_distribution_info_exe); +continue; + } + + // execute the distribution-retrieval command, read output + std::string get_distribution_id_command(get_distribution_info_exe); + get_distribution_id_command += " -i"; + + FILE *file = popen(get_distribution_id_command.c_str(), "r"); + if (!file) { +LLDB_LOGF(log, + "failed to run command: \"%s\", cannot retrieve " + "platform information", + get_distribution_id_command.c_str()); +break; + } + + // retrieve the distribution id string. + char distribution_id[256] = {'\0'}; + if (fgets(distribution_id, sizeof(distribution_id) - 1, file) != + nullptr) { +LLDB_LOGF(log, "distribution id command returned \"%s\"", + distribution_id); + +const char *const distributor_id_key = "Distributor ID:\t"; +if (strstr(distribution_id, distributor_id_key)) { + // strip newlines + std::string id_string(distribution_id + strlen(distributor_id_key)); + llvm::erase(id_string, '\n'); + + // lower case it and convert whitespace to underscores + std::transform( + id_string.begin(), id_string.end(), id_string.begin(), + [](char ch) { return tolower(isspace(ch) ? '_' : ch); }); + + g_fields->m_distribution_id = id_string; + LLDB_LOGF(log, "distribution id set to \"%s\"", +g_fields->m_distribution_id.c_str()); +} else { + LLDB_LOGF(log, "failed to find \"%s\" field in \"%s\"", +distributor_id_key, distribution_id); +} + } else { +LLDB_LOGF(log, + "failed to retrieve distribution id, \"%s\" returned no" + " lines", + get_distribution_id_command.c_str()); + } + + // clean up the file + pclose(file); +} + }); + + return g_fields->m_distribution_id; +} + +FileSpec HostInfoAIX::GetProgramFileSpec() { + static FileSpec g_program_filespec; + + if (!g_program_filespec) { +char exe_path[PATH_MAX]; +ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); +if (len > 0) { + exe_path[len] = 0; + g_program_filespec.SetFile(exe_path, FileSpec::Style::native); +} + } + + return g_program_filespec; +} DavidSpickett wrote: The part inside the `if (!g_...` could be moved to a private static method in HostInfoPosix. But equally, this code is identical to Linux and will very likely remain so. So I'm not bothered by having two copies of it. If I wanted to find out who read `/proc/self`, I'd search for `proc/self` in the codebase which would find both copies. I wouldn't change this unless
[Lldb-commits] [lldb] [lldb][AIX] HostInfoAIX Support (PR #117906)
@@ -0,0 +1,154 @@ +//===-- HostInfoAIX.cpp -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "lldb/Host/aix/HostInfoAIX.h" +#include "lldb/Host/Config.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" + +#include "llvm/Support/Threading.h" + +#include +#include +#include +#include +#include + +#include +#include + +using namespace lldb_private; + +namespace { +struct HostInfoAIXFields { + llvm::once_flag m_distribution_once_flag; + std::string m_distribution_id; +}; +} // namespace + +static HostInfoAIXFields *g_fields = nullptr; + +void HostInfoAIX::Initialize(SharedLibraryDirectoryHelper *helper) { + HostInfoPosix::Initialize(helper); + + g_fields = new HostInfoAIXFields(); +} + +void HostInfoAIX::Terminate() { + assert(g_fields && "Missing call to Initialize?"); + delete g_fields; + g_fields = nullptr; + HostInfoBase::Terminate(); +} + +llvm::StringRef HostInfoAIX::GetDistributionId() { + assert(g_fields && "Missing call to Initialize?"); + // Try to run 'lbs_release -i', and use that response for the distribution + // id. + llvm::call_once(g_fields->m_distribution_once_flag, []() { +Log *log = GetLog(LLDBLog::Host); +LLDB_LOGF(log, "attempting to determine AIX distribution..."); + +// check if the lsb_release command exists at one of the following paths +const char *const exe_paths[] = {"/bin/lsb_release", + "/usr/bin/lsb_release"}; + +for (size_t exe_index = 0; + exe_index < sizeof(exe_paths) / sizeof(exe_paths[0]); ++exe_index) { + const char *const get_distribution_info_exe = exe_paths[exe_index]; + if (access(get_distribution_info_exe, F_OK)) { +// this exe doesn't exist, move on to next exe +LLDB_LOGF(log, "executable doesn't exist: %s", + get_distribution_info_exe); +continue; + } + + // execute the distribution-retrieval command, read output + std::string get_distribution_id_command(get_distribution_info_exe); + get_distribution_id_command += " -i"; + + FILE *file = popen(get_distribution_id_command.c_str(), "r"); + if (!file) { +LLDB_LOGF(log, + "failed to run command: \"%s\", cannot retrieve " + "platform information", + get_distribution_id_command.c_str()); +break; + } + + // retrieve the distribution id string. + char distribution_id[256] = {'\0'}; + if (fgets(distribution_id, sizeof(distribution_id) - 1, file) != + nullptr) { +LLDB_LOGF(log, "distribution id command returned \"%s\"", + distribution_id); + +const char *const distributor_id_key = "Distributor ID:\t"; +if (strstr(distribution_id, distributor_id_key)) { + // strip newlines + std::string id_string(distribution_id + strlen(distributor_id_key)); + llvm::erase(id_string, '\n'); + + // lower case it and convert whitespace to underscores + std::transform( + id_string.begin(), id_string.end(), id_string.begin(), + [](char ch) { return tolower(isspace(ch) ? '_' : ch); }); + + g_fields->m_distribution_id = id_string; + LLDB_LOGF(log, "distribution id set to \"%s\"", +g_fields->m_distribution_id.c_str()); +} else { + LLDB_LOGF(log, "failed to find \"%s\" field in \"%s\"", +distributor_id_key, distribution_id); +} + } else { +LLDB_LOGF(log, + "failed to retrieve distribution id, \"%s\" returned no" + " lines", + get_distribution_id_command.c_str()); + } + + // clean up the file + pclose(file); +} + }); + + return g_fields->m_distribution_id; +} + +FileSpec HostInfoAIX::GetProgramFileSpec() { + static FileSpec g_program_filespec; + + if (!g_program_filespec) { +char exe_path[PATH_MAX]; +ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); +if (len > 0) { + exe_path[len] = 0; + g_program_filespec.SetFile(exe_path, FileSpec::Style::native); +} + } + + return g_program_filespec; +} + +void HostInfoAIX::ComputeHostArchitectureSupport(ArchSpec &arch_32, DavidSpickett wrote: Do you actually need this or do things work if you remove it and rely on HostInfoPosix::ComputeHostArchitectureSupport to get it right? https://github.com/llvm/llvm-project/pull/117906 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists
[Lldb-commits] [lldb] [lldb][Docs] Add equivalents of GDB's "skip" to command map (PR #120740)
https://github.com/kastiglione approved this pull request. thanks! https://github.com/llvm/llvm-project/pull/120740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Docs] Add equivalents of GDB's "skip" to command map (PR #120740)
https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/120740 >From 65de95430fce9315a5d34aec589796818d5cd06f Mon Sep 17 00:00:00 2001 From: David Spickett Date: Fri, 20 Dec 2024 14:38:05 + Subject: [PATCH 1/3] [lldb][Docs] Add equivalent of GDB's "skip" to command map https://sourceware.org/gdb/current/onlinedocs/gdb.html/Skipping-Over-Functions-and-Files.html We can't emulate all the features of that command but we can skip a function by name with some extra steps. As far as I know this only matches function name unlike GDB that can filter on file and line and so on: ``` target.process.thread.step-avoid-regexp -- A regular expression defining functions step-in won't stop in. ``` It's likely it's got some corner cases that don't work, maybe inlining, but it doesn't seem worth going into it here. I don't think we can chain lldb interpreter commands, so I have shown the steps separately. --- lldb/docs/use/map.rst | 17 + 1 file changed, 17 insertions(+) diff --git a/lldb/docs/use/map.rst b/lldb/docs/use/map.rst index fe9c3f53022fad..cb1c266078679e 100644 --- a/lldb/docs/use/map.rst +++ b/lldb/docs/use/map.rst @@ -235,6 +235,23 @@ Do a source level single step in the currently selected thread (lldb) step (lldb) s +Ignore a function when doing a source level single step in +~~ + +.. code-block:: shell + + (gdb) skip abc + Function abc will be skipped when stepping. + +.. code-block:: shell + + (lldb) settings show target.process.thread.step-avoid-regexp + target.process.thread.step-avoid-regexp (regex) = ^std:: + (lldb) settings set target.process.thread.step-avoid-regexp (^std::)|(^abc) + +Get the default value, make it into a capture group, then add another capture +group for the new function name. + Do a source level single step over in the currently selected thread ~~~ >From feb68917b39e1ed559ce98350e08a50415ab9b49 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Fri, 20 Dec 2024 15:23:44 + Subject: [PATCH 2/3] note thread step-in and sif --- lldb/docs/use/map.rst | 17 + 1 file changed, 17 insertions(+) diff --git a/lldb/docs/use/map.rst b/lldb/docs/use/map.rst index cb1c266078679e..e66b18a2e06fd8 100644 --- a/lldb/docs/use/map.rst +++ b/lldb/docs/use/map.rst @@ -252,6 +252,23 @@ Ignore a function when doing a source level single step in Get the default value, make it into a capture group, then add another capture group for the new function name. +You can ignore a function once using: + +.. code-block:: shell + + (lldb) thread step-in -r ^abc + +Or you can do the opposite, only step into functions with a certain name: + +.. code-block:: shell + + (lldb) sif abc + # Which is equivalent to: + (lldb) thread step-in -t abc + +``thread step-in`` has more options which cover some of ``skip``'s other +features. See ``help thread step-in`` for details. + Do a source level single step over in the currently selected thread ~~~ >From fc44d2baf4fd360da926018099d56db6be303e55 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Fri, 3 Jan 2025 14:09:58 + Subject: [PATCH 3/3] address review comments --- lldb/docs/use/map.rst | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lldb/docs/use/map.rst b/lldb/docs/use/map.rst index e66b18a2e06fd8..ed285b2d1f6e90 100644 --- a/lldb/docs/use/map.rst +++ b/lldb/docs/use/map.rst @@ -247,10 +247,7 @@ Ignore a function when doing a source level single step in (lldb) settings show target.process.thread.step-avoid-regexp target.process.thread.step-avoid-regexp (regex) = ^std:: - (lldb) settings set target.process.thread.step-avoid-regexp (^std::)|(^abc) - -Get the default value, make it into a capture group, then add another capture -group for the new function name. + (lldb) settings set target.process.thread.step-avoid-regexp ^std::|^abc You can ignore a function once using: @@ -258,10 +255,11 @@ You can ignore a function once using: (lldb) thread step-in -r ^abc -Or you can do the opposite, only step into functions with a certain name: +Or you can do the opposite, only step into functions matching a certain name: .. code-block:: shell + # Step in if abc is a substring of the function name. (lldb) sif abc # Which is equivalent to: (lldb) thread step-in -t abc ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Docs] Add equivalents of GDB's "skip" to command map (PR #120740)
@@ -235,6 +235,23 @@ Do a source level single step in the currently selected thread (lldb) step (lldb) s +Ignore a function when doing a source level single step in +~~ + +.. code-block:: shell + + (gdb) skip abc + Function abc will be skipped when stepping. + +.. code-block:: shell + + (lldb) settings show target.process.thread.step-avoid-regexp + target.process.thread.step-avoid-regexp (regex) = ^std:: + (lldb) settings set target.process.thread.step-avoid-regexp (^std::)|(^abc) DavidSpickett wrote: Done that instead. https://github.com/llvm/llvm-project/pull/120740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][Docs] Add equivalents of GDB's "skip" to command map (PR #120740)
@@ -235,6 +235,40 @@ Do a source level single step in the currently selected thread (lldb) step (lldb) s +Ignore a function when doing a source level single step in +~~ + +.. code-block:: shell + + (gdb) skip abc + Function abc will be skipped when stepping. + +.. code-block:: shell + + (lldb) settings show target.process.thread.step-avoid-regexp + target.process.thread.step-avoid-regexp (regex) = ^std:: + (lldb) settings set target.process.thread.step-avoid-regexp (^std::)|(^abc) + +Get the default value, make it into a capture group, then add another capture +group for the new function name. + +You can ignore a function once using: + +.. code-block:: shell + + (lldb) thread step-in -r ^abc + +Or you can do the opposite, only step into functions with a certain name: + +.. code-block:: shell + + (lldb) sif abc + # Which is equivalent to: + (lldb) thread step-in -t abc DavidSpickett wrote: Noted that just before `sif`. https://github.com/llvm/llvm-project/pull/120740 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Some base #if _AIX changes of a minimal lldb build (PR #120979)
@@ -1226,7 +1226,7 @@ bool lldb_private::formatters::ObjCSELSummaryProvider( time_t lldb_private::formatters::GetOSXEpoch() { static time_t epoch = 0; if (!epoch) { -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(_AIX) DavidSpickett wrote: This would just return 0 on Windows or AIX, but your change isn't making that any worse so it's fine. I think the side effect is printing an `NSDate` while debugging Mac OS from either would give the wrong result. Something that is clearly done rarely, probably never. https://github.com/llvm/llvm-project/pull/120979 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Some base #if _AIX changes of a minimal lldb build (PR #120979)
@@ -715,7 +715,7 @@ ConnectionFileDescriptor::ConnectFD(llvm::StringRef s, ConnectionStatus ConnectionFileDescriptor::ConnectFile( llvm::StringRef s, socket_id_callback_type socket_id_callback, Status *error_ptr) { -#if LLDB_ENABLE_POSIX +#if LLDB_ENABLE_POSIX && !defined(_AIX) DavidSpickett wrote: I'm thinking about what this implies. Which is that while AIX is Posix, it is not Posix in the specific way this code needs. Can you tell me what specifically about the following code does not work on AIX? (I doubt it will be worth changing the meaning of `LLDB_ENABLE_POSIX`, but perhaps we should note what part of this code doesn't work on AIX) https://github.com/llvm/llvm-project/pull/120979 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][AIX] Some base #if _AIX changes of a minimal lldb build (PR #120979)
@@ -16,6 +16,9 @@ #include #include #include +#ifdef _AIX +#include DavidSpickett wrote: First time I've heard that there is string.h and strings.h. What parts of strings.h were needed here? https://github.com/llvm/llvm-project/pull/120979 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits