espressif / openocd-esp32

OpenOCD branch with ESP32 JTAG support
Other
361 stars 132 forks source link

OpenOCD halts CPU when connecting to gdb-server (OCD-979) #330

Closed ghost closed 3 months ago

ghost commented 4 months ago

OpenOCD version

v0.12.0-esp32-20240318

Operating System

Windows 10

Using an IDE ?

VScode esp-idf extension

OpenOCD command line

openocd -f esp32s3-builtin.cfg

ESP-IDF version

v4.4

Problem Description

During the development of an open source project, we wanted to use the gdb-server to extract data from esp32 RAM. Then we fell into an issue, where the application successfully extracts the data, but when we connect to the gdb socket the target halts. This happens before sending any gdb commands over the tcp/ip gdb protocol. We wish to not make the target halt when the attach happens, so we would be happy if you could help us configure OpenOCD for esp32, so that the attachment does not halt the target. Thanks!

Debug Logs

No response

Expected behavior

Custom OpenOCD 'cfg' file as to not halt the target when the attach happens.

Screenshots

No response

erhankur commented 4 months ago

To avoid halt, you can comment out https://github.com/espressif/openocd-esp32/blob/master/tcl/target/esp_common.cfg#L195 and https://github.com/espressif/openocd-esp32/blob/master/tcl/target/esp_common.cfg#L214

As the explanation says, halt is needed for the flash probe. That means, you need to disable the flash support.

openocd -c "set ESP_FLASH_SIZE 0" -f board/esp32s3-builtin.cfg

ghost commented 4 months ago

Hi, thank you @erhankur for your help. When following the steps you mentioned, and then trying to connect to GDB server, we ran into an issue. These are the steps we took:

  1. Comment out both "halt 1000" commands
  2. Added "set ESP_FLASH_SIZE 0" to the arg list for OpenOCD
  3. Started the OpenOCD server
  4. Tried to connect to GDB server
  5. Winsocket function recv() returns value 0 -> Connection to the server has been gracefully closed.

However, it is interesting that this does not happen if the MCU is halted already.

erhankur commented 4 months ago

Sorry no idea what is happening. If you can share the verbose OpenOCD logs, I can suggest something more.

openocd -c "set ESP_FLASH_SIZE 0" -f board/esp32s3-builtin.cfg -d3 -l log.txt
ghost commented 4 months ago

Sorry for the wait @erhankur , I am attaching the log file. logfile.log

erhankur commented 4 months ago

Thanks for the log. We can comment out configure_event_gdb_attach call inside configure_openocd_events.

proc configure_openocd_events { ARCH } {
    if { $ARCH == "riscv" } {
        configure_event_halted
        configure_shutdown_command
    }
    configure_event_examine_end
    configure_event_reset_assert_post
    # configure_event_gdb_attach
}

We disabled flash support so we don't need mem prot check anymore. After that, there is nothing to do in the gdb attach event.

erhankur commented 3 months ago

@Stefasaurus Can we close this issue now? Do you have any other question?

erhankur commented 3 months ago

Closed. Feel free to re-open if you have any other question.