generate_debug_scripts.cmake 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. function(___output_debug_target bin_name )
  2. file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" cm_build_dir)
  3. if( "${bin_name}" STREQUAL "_" )
  4. set(debug_file "dbg_project" )
  5. else()
  6. set(debug_file "dbg_${bin_name}" )
  7. endif()
  8. set(flash_debug_file "${CMAKE_BINARY_DIR}/flash_${debug_file}" )
  9. set(debug_file "${CMAKE_BINARY_DIR}/${debug_file}")
  10. list(APPEND dbg_cmds "target extended-remote :3333")
  11. list(APPEND dbg_cmds "set remote hardware-watchpoint-limit 2")
  12. list(APPEND dbg_cmds "mon reset halt")
  13. list(APPEND dbg_cmds "flushregs")
  14. set(flash_args_file "${cm_build_dir}/flash_project_args" )
  15. file(READ ${flash_args_file} flash_args)
  16. STRING(REGEX REPLACE "\n" ";" SPLIT "${flash_args}")
  17. set(line_prefix "mon program_esp32 ${cm_build_dir}/" )
  18. foreach(flash_arg_line ${SPLIT})
  19. string(REGEX MATCH "^(0[xX][^ ]*)[ ]*([^ ]*)" out_matches "${flash_arg_line}")
  20. if( ${CMAKE_MATCH_COUNT} GREATER 0 )
  21. set(found_offset "${CMAKE_MATCH_1}")
  22. set(found_bin "${CMAKE_MATCH_2}")
  23. if( ( "${found_bin}" MATCHES "${bin_name}" ) OR ( "${bin_name}" STREQUAL "_" ) )
  24. list(APPEND flash_dbg_cmds "${line_prefix}${found_bin} ${found_offset}")
  25. get_filename_component(found_bin_name ${found_bin} NAME_WLE )
  26. list(APPEND dbg_cmds "symbol-file ${line_prefix}${found_bin_name}.elf")
  27. endif()
  28. if( ( "${bin_name}" MATCHES "recovery" ) AND ( "${found_bin}" MATCHES "ota_data_initial" ) )
  29. # reset OTADATA to force reloading recovery
  30. list(APPEND flash_dbg_cmds "${line_prefix}${found_bin} ${found_offset}")
  31. endif()
  32. if( ( "${found_bin}" MATCHES "${bin_name}" ) AND NOT ( "${bin_name}" STREQUAL "_" ) )
  33. list(APPEND dbg_cmds "mon esp32 appimage_offset ${found_offset}")
  34. endif()
  35. endif()
  36. endforeach()
  37. list(APPEND dbg_cmds_end "thb app_main")
  38. list(APPEND dbg_cmds_end "c")
  39. list(APPEND full_dbg_cmds "${dbg_cmds}")
  40. list(APPEND full_dbg_cmds "${dbg_cmds_end}")
  41. list(APPEND full_flash_dbg_cmds "${dbg_cmds}")
  42. list(APPEND full_flash_dbg_cmds "${flash_dbg_cmds}")
  43. list(APPEND full_flash_dbg_cmds "${dbg_cmds_end}")
  44. STRING(REGEX REPLACE ";" "\n" dbg_cmds_end "${dbg_cmds_end}")
  45. STRING(REGEX REPLACE ";" "\n" full_dbg_cmds "${full_dbg_cmds}")
  46. STRING(REGEX REPLACE ";" "\n" full_flash_dbg_cmds "${full_flash_dbg_cmds}")
  47. # message("Writing: ${debug_file} with ${full_dbg_cmds}")
  48. file(WRITE "${debug_file}" "${full_dbg_cmds}")
  49. # message("Writing: ${flash_debug_file} with : ${full_flash_dbg_cmds}")
  50. file(WRITE "${flash_debug_file}" "${full_flash_dbg_cmds}")
  51. endfunction()
  52. message("Generating debug script files")
  53. ___output_debug_target("_")
  54. ___output_debug_target("squeezelite")
  55. ___output_debug_target("recovery")