Skip to content

Commit

Permalink
format code to pass CI
Browse files Browse the repository at this point in the history
Signed-off-by: Neo Xu <[email protected]>
  • Loading branch information
XuNeo authored and xiaoxiang781216 committed Nov 20, 2024
1 parent 96a3bc2 commit edc410f
Show file tree
Hide file tree
Showing 7 changed files with 434 additions and 203 deletions.
2 changes: 2 additions & 0 deletions tools/gdb/gcore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
############################################################################
# tools/gdb/gcore.py
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
Expand Down
8 changes: 3 additions & 5 deletions tools/gdb/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,14 @@ def invoke(self, arg, from_tty):
argv = gdb.string_to_argv(arg)

if len(argv) != 3:
gdb.write("listforentry takes three arguments"
"head, type, member\n")
gdb.write("listforentry takes three arguments" "head, type, member\n")
gdb.write("eg: listforentry &g_list 'struct type' 'node '\n")
return

i = 0
for entry in list_for_each_entry(
gdb.parse_and_eval(argv[0]),
gdb.lookup_type(argv[1]).pointer(),
argv[2]):
gdb.parse_and_eval(argv[0]), gdb.lookup_type(argv[1]).pointer(), argv[2]
):
gdb.write(f"{i}: ({argv[1]} *){entry}\n")
gdb.execute(f"print *({argv[1]} *){entry}")
i += 1
Expand Down
88 changes: 63 additions & 25 deletions tools/gdb/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,60 @@
import tempfile

PUNCTUATORS = [
"\[", "\]", "\(", "\)", "\{", "\}", "\?", ";", ",", "~",
"\.\.\.", "\.",
"\-\>", "\-\-", "\-\=", "\-",
"\+\+", "\+\=", "\+",
"\*\=", "\*",
"\!\=", "\!",
"\&\&", "\&\=", "\&",
"\/\=", "\/",
"\%\>", "%:%:", "%:", "%=", "%",
"\^\=", "\^",
"\#\#", "\#",
"\:\>", "\:",
"\|\|", "\|\=", "\|",
"<<=", "<<", "<=", "<:", "<%", "<",
">>=", ">>", ">=", ">",
"\=\=", "\=",
"\[",
"\]",
"\(",
"\)",
"\{",
"\}",
"\?",
";",
",",
"~",
"\.\.\.",
"\.",
"\-\>",
"\-\-",
"\-\=",
"\-",
"\+\+",
"\+\=",
"\+",
"\*\=",
"\*",
"\!\=",
"\!",
"\&\&",
"\&\=",
"\&",
"\/\=",
"\/",
"\%\>",
"%:%:",
"%:",
"%=",
"%",
"\^\=",
"\^",
"\#\#",
"\#",
"\:\>",
"\:",
"\|\|",
"\|\=",
"\|",
"<<=",
"<<",
"<=",
"<:",
"<%",
"<",
">>=",
">>",
">=",
">",
"\=\=",
"\=",
]


Expand Down Expand Up @@ -92,10 +130,8 @@ def fetch_macro_info(file):

# # os.system(f"readelf -wm {file} > {output}")
process = subprocess.Popen(
f"readelf -wm {file}",
shell=True,
stdout=f1,
stderr=subprocess.STDOUT)
f"readelf -wm {file}", shell=True, stdout=f1, stderr=subprocess.STDOUT
)

process.communicate()
errcode = process.returncode
Expand All @@ -108,11 +144,12 @@ def fetch_macro_info(file):
p = re.compile(".*macro[ ]*:[ ]*([\S]+\(.*?\)|[\w]+)[ ]*(.*)")
macros = {}

with open(f1.name, 'rb') as f2:
with open(f1.name, "rb") as f2:
for line in f2.readlines():
line = line.decode("utf-8")
if not line.startswith(" DW_MACRO_define") and \
not line.startswith(" DW_MACRO_undef"):
if not line.startswith(" DW_MACRO_define") and not line.startswith(
" DW_MACRO_undef"
):
continue

if not parse_macro(line, macros, p):
Expand All @@ -123,8 +160,9 @@ def fetch_macro_info(file):

def split_tokens(expr):
p = "(" + "|".join(PUNCTUATORS) + ")"
res = list(filter(lambda e : e != "",
map(lambda e: e.rstrip().lstrip(), re.split(p, expr))))
res = list(
filter(lambda e: e != "", map(lambda e: e.rstrip().lstrip(), re.split(p, expr)))
)
return res


Expand Down
Loading

0 comments on commit edc410f

Please sign in to comment.