mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 09:49:21 +08:00
gdb/macro: fix cached macro info is outdated
Use the file hash instead to avoid file name conflicts Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
parent
aa74ba5ace
commit
6d0d4458cd
1 changed files with 11 additions and 3 deletions
|
@ -37,9 +37,11 @@
|
||||||
#
|
#
|
||||||
# Currently, we are using the second method.
|
# Currently, we are using the second method.
|
||||||
|
|
||||||
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
from os import path
|
||||||
|
|
||||||
PUNCTUATORS = [
|
PUNCTUATORS = [
|
||||||
"\[",
|
"\[",
|
||||||
|
@ -120,18 +122,24 @@ def parse_macro(line, macros, pattern):
|
||||||
|
|
||||||
|
|
||||||
def fetch_macro_info(file):
|
def fetch_macro_info(file):
|
||||||
if not os.path.isfile(file):
|
if not path.isfile(file):
|
||||||
raise FileNotFoundError("No given ELF target found")
|
raise FileNotFoundError("No given ELF target found")
|
||||||
|
|
||||||
# FIXME: we don't use subprocess here because
|
# FIXME: we don't use subprocess here because
|
||||||
# it's broken on some GDB distribution :(, I haven't
|
# it's broken on some GDB distribution :(, I haven't
|
||||||
# found a solution to it.
|
# found a solution to it.
|
||||||
|
|
||||||
cache = os.path.splitext(file)[0] + ".macro"
|
with open(file, "rb") as f:
|
||||||
if not os.path.isfile(cache):
|
hash = hashlib.md5(f.read()).hexdigest()
|
||||||
|
|
||||||
|
cache = path.join(path.dirname(path.abspath(file)), f"{hash}.macro")
|
||||||
|
if not path.isfile(cache):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
os.system(f"readelf -wm {file} > {cache}")
|
os.system(f"readelf -wm {file} > {cache}")
|
||||||
print(f"readelf took {time.time() - start:.1f} seconds")
|
print(f"readelf took {time.time() - start:.1f} seconds")
|
||||||
|
print(f"Cache macro info to {cache}")
|
||||||
|
else:
|
||||||
|
print(f"Load macro info from {cache}")
|
||||||
|
|
||||||
p = re.compile(".*macro[ ]*:[ ]*([\S]+\(.*?\)|[\w]+)[ ]*(.*)")
|
p = re.compile(".*macro[ ]*:[ ]*([\S]+\(.*?\)|[\w]+)[ ]*(.*)")
|
||||||
macros = {}
|
macros = {}
|
||||||
|
|
Loading…
Reference in a new issue