您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

gdb.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. def main():
  2. import subprocess
  3. import glob
  4. import sys # Import sys to access command line arguments
  5. # 获取当前目录中的所有 .out 文件
  6. out_files = glob.glob('*.out')
  7. if not out_files:
  8. out_files = glob.glob('*.axf')
  9. if not out_files:
  10. print("No .out files found in the current directory.")
  11. return
  12. elif len(out_files) > 1:
  13. print("Multiple .out files found. Using the first one found.")
  14. out_file = out_files[0] # 使用找到的第一个 .out 文件
  15. # 检查是否已提供 dump.txt 作为第一个参数
  16. if len(sys.argv) > 1 and sys.argv[1] == 'dump.txt':
  17. print("Using provided dump.txt file.")
  18. else:
  19. # 获取用户的多行输入
  20. print("Enter the input for mcu_coredump.exe (Ctrl-Z then Enter to finish):")
  21. user_input = []
  22. while True:
  23. try:
  24. line = input()
  25. except EOFError:
  26. break
  27. user_input.append(line)
  28. # 将输入写入文件
  29. with open('dump.txt', 'w') as file:
  30. file.write('\n'.join(user_input))
  31. # 运行 mcu_coredump.exe
  32. subprocess.run(['mcu_coredump.exe', 'dump.txt', 'core'])
  33. # 运行 GDB
  34. print(f"Running GDB to analyze the core dump using {out_file}...")
  35. subprocess.run(['arm-none-eabi-gdb.exe', out_file, 'core'])
  36. if __name__ == "__main__":
  37. main()