generate_debug_scripts.cmake 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. set(flash_args_file "${cm_build_dir}/flash_project_args" )
  11. set(line_prefix "mon program_esp32 ${cm_build_dir}/" )
  12. file(READ ${flash_args_file} flash_args)
  13. list(APPEND dbg_cmds "target remote :3333")
  14. list(APPEND dbg_cmds "mon reset halt")
  15. list(APPEND dbg_cmds "flushregs")
  16. list(APPEND dbg_cmds "set remote hardware-watchpoint-limit 2")
  17. STRING(REGEX REPLACE "\n" ";" SPLIT "${flash_args}")
  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. endif()
  26. if( ( "${bin_name}" MATCHES "recovery" ) AND ( "${found_bin}" MATCHES "ota_data_initial" ) )
  27. # reset OTADATA to force reloading recovery
  28. list(APPEND flash_dbg_cmds "${line_prefix}${found_bin} ${found_offset}")
  29. endif()
  30. if( ( "${found_bin}" MATCHES "${bin_name}" ) AND NOT ( "${bin_name}" STREQUAL "_" ) )
  31. list(APPEND dbg_cmds "mon esp32 appimage_offset ${found_offset}")
  32. endif()
  33. endif()
  34. endforeach()
  35. list(APPEND full_dbg_cmds "${dbg_cmds}")
  36. list(APPEND full_dbg_cmds "${dbg_cmds_end}")
  37. list(APPEND full_flash_dbg_cmds "${dbg_cmds}")
  38. list(APPEND full_flash_dbg_cmds "${flash_dbg_cmds}")
  39. list(APPEND full_flash_dbg_cmds "${dbg_cmds_end}")
  40. STRING(REGEX REPLACE ";" "\n" dbg_cmds_end "${dbg_cmds_end}")
  41. STRING(REGEX REPLACE ";" "\n" full_dbg_cmds "${full_dbg_cmds}")
  42. STRING(REGEX REPLACE ";" "\n" full_flash_dbg_cmds "${full_flash_dbg_cmds}")
  43. # message("Writing: ${debug_file} with ${full_dbg_cmds}")
  44. file(WRITE "${debug_file}" "${full_dbg_cmds}")
  45. # message("Writing: ${flash_debug_file} with : ${full_flash_dbg_cmds}")
  46. file(WRITE "${flash_debug_file}" "${full_flash_dbg_cmds}")
  47. endfunction()
  48. message("Generating debug script files")
  49. ___output_debug_target("_")
  50. ___output_debug_target("squeezelite")
  51. ___output_debug_target("recovery")