Skip to content

Commit

Permalink
Merge pull request #207 from jxlpzqc/patch-1
Browse files Browse the repository at this point in the history
Fix older gdb breakpoints parse bugs
  • Loading branch information
sakhnik authored Aug 12, 2024
2 parents 9b149e6 + 2ff04a7 commit 2ab24b3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 16 deletions.
42 changes: 34 additions & 8 deletions lib/gdb_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _get_breaks(self, fname: str):

try:
for path, line, bid in self._get_breaks_provider():
if fname == os.path.normpath(path):
if fname.endswith(os.path.normpath(path)):
breaks.setdefault(line, []).append(bid)
except AttributeError:
self.fallback_to_parsing = True
Expand Down Expand Up @@ -178,15 +178,41 @@ def _enum_breaks_fallback(self):
# on the second line if the screen is too narrow.
bid = None
response = gdb.execute('info breakpoints', False, True)
for line in re.split(r"[\n\r]+", response):
fields = re.split(r"[\s]+", line)

if len(fields) >= 5 and re.match("0x[0-9a-zA-Z]+", fields[4]):
if fields[3] != 'y': # Is enabled?
bid = None
else:
bid = re.match("[^.]+", fields[0]).group(0)
column_idx = {}
header = response.splitlines()[0]
contents = response.splitlines()[1:]

for f in re.finditer(r"(\w+)\s*", header):
s, e, str = f.start(), f.end(), f.group(1)
e = None if e == len(header) else e
column_idx[str] = (s, e)

def get_column_value(line, column_name):
if column_name not in column_idx:
return ""
s, e = column_idx[column_name]
return line[s:e].strip()

last_enabled = False

for line in contents:
bid, enabled, address, what = (
get_column_value(line, "Num"),
get_column_value(line, "Enb"),
get_column_value(line, "Address"),
get_column_value(line, "What"),
)

if enabled == '':
enabled = last_enabled

if not bid or enabled != 'y' or re.match(r"0x[0-9a-zA-Z]+", address) is None:
continue

bid = bid.split(".")[0]

fields = re.split(r"\s+", what)
if len(fields) >= 2 and fields[-2] == "at":
# file.cpp:line
m = re.match(r"^([^:]+):(\d+)$", fields[-1])
Expand Down
27 changes: 24 additions & 3 deletions test/10_generic_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ describe("generic", function()

local function check_signs(signs)
-- different for different compilers
return vim.deep_equal(signs, {cur = 'test.cpp:17'}) or vim.deep_equal(signs, {cur = 'test.cpp:19'})
local lines = {17, 19, 20}
for _, line in ipairs(lines) do
if vim.deep_equal(signs, {cur = 'test.cpp:' .. line}) then
return true
end
end
return false
end
assert.is_true(eng.wait_for(eng.get_signs, check_signs))

Expand Down Expand Up @@ -70,7 +76,7 @@ describe("generic", function()
eng.feed('<esc>')
assert.is_true(eng.wait_running(5000))
eng.feed(':GdbInterrupt\n')
if not utils.is_windows then
if utils.is_linux then
assert.is_true(eng.wait_signs({cur = 'test.cpp:22'}))
else
-- Most likely to break in the kernel code
Expand Down Expand Up @@ -180,7 +186,22 @@ describe("generic", function()
eng.feed('n<cr>')
assert.is_true(eng.wait_signs({cur = 'test.cpp:19'}))
eng.feed('<cr>')
assert.is_true(eng.wait_signs({cur = 'test.cpp:17'}))

if utils.is_darwin then
local function check_signs(signs)
-- different for different compilers
local lines = {17, 20}
for _, line in ipairs(lines) do
if vim.deep_equal(signs, {cur = 'test.cpp:' .. line}) then
return true
end
end
return false
end
assert.is_true(eng.wait_for(eng.get_signs, check_signs))
else
assert.is_true(eng.wait_signs({cur = 'test.cpp:17'}))
end
end)
end)

Expand Down
2 changes: 2 additions & 0 deletions test/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
Prerequisites()

test_cmd = ["nvim", "-l", "run-tests.lua", ".", "--no-keep-going"]
# Use the following command to see neovim screen
# test_cmd = ["python", "nvim.py", "+luafile main.lua"]
print(f"Run `{' '.join(test_cmd)}`")
res = subprocess.run(test_cmd)
if res.returncode != 0:
Expand Down
14 changes: 9 additions & 5 deletions utils/testenv_darwin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
import subprocess
import urllib.request

Expand All @@ -16,14 +17,17 @@ def __init__(self, url: str):

subprocess.run('pip install --user six', shell=True, check=True)

urllib.request.urlretrieve(f"{url}/nvim-macos.tar.gz",
"nvim-macos.tar.gz")
# Macos may be running on arm64
machine = platform.machine()

urllib.request.urlretrieve(f"{url}/nvim-macos-{machine}.tar.gz",
f"nvim-macos-{machine}.tar.gz")
subprocess.run(
r'''
tar -xf nvim-macos.tar.gz
f'''
tar -xf nvim-macos-{machine}.tar.gz
cat >"$HOME/bin/nvim" <<EOF
#!/bin/bash
$(pwd)/nvim-macos/bin/nvim "\$@"
$(pwd)/nvim-macos-{machine}/bin/nvim "\\$@"
EOF
chmod +x "$HOME/bin/nvim"
''',
Expand Down

0 comments on commit 2ab24b3

Please sign in to comment.