cl: switch debug symbols with LLGO_DEBUG
This commit is contained in:
@@ -3,15 +3,17 @@
|
||||
### Build with debug info
|
||||
|
||||
```shell
|
||||
llgo build -o cl/_testdata/debug/out -dbg ./cl/_testdata/debug
|
||||
LLGO_DEBUG=1 llgo build -o cl/_testdata/debug/out ./cl/_testdata/debug
|
||||
```
|
||||
|
||||
### Debug with lldb
|
||||
|
||||
```shell
|
||||
lldb -O "command script import _lldb/llgo_plugin.py" ./cl/_testdata/debug/out
|
||||
_lldb/runlldb.sh ./cl/_testdata/debug/out
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```shell
|
||||
/opt/homebrew/bin/lldb -O "command script import _lldb/llgo_plugin.py" ./cl/_testdata/debug/out
|
||||
# github.com/goplus/llgo/cl/_testdata/debug
|
||||
|
||||
@@ -11,7 +11,8 @@ find_lldb() {
|
||||
|
||||
for lldb_path in "${lldb_paths[@]}"; do
|
||||
if command -v "$lldb_path" >/dev/null 2>&1; then
|
||||
local version=$("$lldb_path" --version | grep -oE '[0-9]+' | head -1)
|
||||
local version
|
||||
version=$("$lldb_path" --version | grep -oE '[0-9]+' | head -1)
|
||||
if [ "$version" -ge 18 ]; then
|
||||
echo "$lldb_path"
|
||||
return 0
|
||||
@@ -25,12 +26,13 @@ find_lldb() {
|
||||
|
||||
# Find LLDB 18+
|
||||
LLDB_PATH=$(find_lldb)
|
||||
export LLDB_PATH
|
||||
|
||||
# Default package path
|
||||
DEFAULT_PACKAGE_PATH="./cl/_testdata/debug"
|
||||
export DEFAULT_PACKAGE_PATH="./cl/_testdata/debug"
|
||||
|
||||
# Function to build the project
|
||||
build_project() {
|
||||
local package_path="$1"
|
||||
go run ./cmd/llgo build -o "${package_path}/out" -dbg "${package_path}"
|
||||
}
|
||||
LLGO_DEBUG=1 go run ./cmd/llgo build -o "${package_path}/out" "${package_path}"
|
||||
}
|
||||
|
||||
@@ -3,16 +3,10 @@
|
||||
set -e
|
||||
|
||||
# Source common functions and variables
|
||||
# shellcheck source=./_lldb/common.sh
|
||||
source "$(dirname "$0")/common.sh"
|
||||
|
||||
# Check if a package path is provided as an argument
|
||||
package_path="$DEFAULT_PACKAGE_PATH"
|
||||
if [ $# -eq 1 ]; then
|
||||
package_path="$1"
|
||||
fi
|
||||
|
||||
# Build the project
|
||||
build_project "$package_path"
|
||||
executable="$1"
|
||||
|
||||
# Run LLDB
|
||||
"$LLDB_PATH" "${package_path}/out"
|
||||
"$LLDB_PATH" "$executable"
|
||||
|
||||
@@ -91,7 +91,7 @@ class LLDBDebugger:
|
||||
bp = self.target.BreakpointCreateByLocation(file_spec, line_number)
|
||||
if not bp.IsValid():
|
||||
raise LLDBTestException(f"Failed to set breakpoint at {
|
||||
file_spec}:{line_number}")
|
||||
file_spec}: {line_number}")
|
||||
return bp
|
||||
|
||||
def run_to_breakpoint(self) -> None:
|
||||
@@ -225,7 +225,7 @@ def execute_tests(executable_path: str, test_cases: List[TestCase], verbose: boo
|
||||
try:
|
||||
if verbose:
|
||||
log(f"Setting breakpoint at {
|
||||
test_case.source_file}:{test_case.end_line}")
|
||||
test_case.source_file}: {test_case.end_line}")
|
||||
debugger.setup()
|
||||
debugger.set_breakpoint(test_case.source_file, test_case.end_line)
|
||||
debugger.run_to_breakpoint()
|
||||
@@ -269,6 +269,7 @@ def run_tests(executable_path: str, source_files: List[str], verbose: bool, inte
|
||||
|
||||
results = execute_tests(executable_path, test_cases,
|
||||
verbose, interactive, plugin_path)
|
||||
print_test_results(results)
|
||||
|
||||
if results.total != results.passed:
|
||||
os._exit(1)
|
||||
@@ -331,14 +332,7 @@ def execute_single_variable_test(debugger: LLDBDebugger, test: Test) -> TestResu
|
||||
)
|
||||
|
||||
|
||||
def print_test_results(results: TestResults, verbose: bool) -> None:
|
||||
for case_result in results.case_results:
|
||||
case = case_result.test_case
|
||||
loc = f"{case.source_file}:{case.start_line}-{case.end_line}"
|
||||
log(f"\nTest case: {loc} in function '{case_result.function}'")
|
||||
for result in case_result.results:
|
||||
print_test_result(result, verbose)
|
||||
|
||||
def print_test_results(results: TestResults) -> None:
|
||||
log("\nTest results:")
|
||||
log(f" Total tests: {results.total}")
|
||||
log(f" Passed tests: {results.passed}")
|
||||
|
||||
Reference in New Issue
Block a user