49
49
#include "xtensa_algorithm.h"
50
50
#include "esp_xtensa.h"
51
51
#include "esp_xtensa_apptrace.h"
52
+ #include "esp_xtensa_smp.h"
52
53
#include "esp32_apptrace.h"
53
54
54
55
@@ -2737,6 +2738,27 @@ int esp_gcov_poll(struct target *target, void *priv)
2737
2738
return res ;
2738
2739
}
2739
2740
2741
+ static struct esp_dbg_stubs * get_stubs_from_target (struct target * * target )
2742
+ {
2743
+ struct esp_dbg_stubs * dbg_stubs = NULL ;
2744
+
2745
+ if ((* target )-> smp ) {
2746
+ struct target_list * head ;
2747
+ struct target * curr ;
2748
+ foreach_smp_target (head , (* target )-> head ) {
2749
+ curr = head -> target ;
2750
+ dbg_stubs = & (target_to_esp_xtensa (curr )-> dbg_stubs );
2751
+ if (target_was_examined (curr ) && dbg_stubs -> base &&
2752
+ dbg_stubs -> entries_count > 0 ) {
2753
+ * target = curr ;
2754
+ break ;
2755
+ }
2756
+ }
2757
+ } else
2758
+ dbg_stubs = & (target_to_esp_xtensa (* target )-> dbg_stubs );
2759
+ return dbg_stubs ;
2760
+ }
2761
+
2740
2762
COMMAND_HANDLER (esp32_cmd_gcov )
2741
2763
{
2742
2764
static struct esp32_apptrace_cmd_ctx s_at_cmd_ctx ;
@@ -2762,68 +2784,63 @@ COMMAND_HANDLER(esp32_cmd_gcov)
2762
2784
LOG_ERROR ("Failed to init cmd ctx (%d)!" , res );
2763
2785
return res ;
2764
2786
}
2765
- if (dump ) {
2766
- /* command can be invoked on unexamined core, if so find examined one */
2767
- if (target -> smp && !target_was_examined (target )) {
2768
- struct target_list * head ;
2769
- struct target * curr ;
2770
- LOG_WARNING ("Current target '%s' was not examined!" , target_name (target ));
2771
- foreach_smp_target (head , target -> head ) {
2772
- curr = head -> target ;
2773
- if (target_was_examined (curr )) {
2774
- target = curr ;
2775
- LOG_WARNING ("Run command on target '%s'" ,
2776
- target_name (target ));
2777
- break ;
2778
- }
2787
+ /* command can be invoked on unexamined core, if so find examined one */
2788
+ if (target -> smp && !target_was_examined (target )) {
2789
+ struct target_list * head ;
2790
+ struct target * curr = target ;
2791
+ LOG_WARNING ("Current target '%s' was not examined!" , target_name (target ));
2792
+ foreach_smp_target (head , target -> head ) {
2793
+ curr = head -> target ;
2794
+ if (target_was_examined (curr )) {
2795
+ LOG_WARNING ("Run command on target '%s'" ,
2796
+ target_name (target ));
2797
+ break ;
2779
2798
}
2780
2799
}
2781
- old_state = target -> state ;
2800
+ if (curr == target ) {
2801
+ LOG_ERROR ("There is no examined core to run command!" );
2802
+ return ERROR_FAIL ;
2803
+ }
2804
+ target = curr ;
2805
+ }
2806
+ old_state = target -> state ;
2807
+ if (dump ) {
2782
2808
/* connect */
2783
- res = esp32_apptrace_connect_targets (& s_at_cmd_ctx , true, dump );
2809
+ res = esp32_apptrace_connect_targets (& s_at_cmd_ctx , true, true );
2784
2810
if (res != ERROR_OK ) {
2785
2811
LOG_ERROR ("Failed to connect to targets (%d)!" , res );
2786
2812
esp_gcov_cmd_cleanup (& s_at_cmd_ctx );
2787
2813
return res ;
2788
2814
}
2789
2815
esp_gcov_poll (target , & s_at_cmd_ctx );
2790
2816
} else {
2791
- struct esp_dbg_stubs * dbg_stubs = NULL ;
2792
- if (target -> smp ) {
2793
- struct target_list * head ;
2794
- struct target * curr ;
2795
- foreach_smp_target (head , target -> head ) {
2796
- curr = head -> target ;
2797
- dbg_stubs = & (target_to_esp_xtensa (curr )-> dbg_stubs );
2798
- if (target_was_examined (curr ) && dbg_stubs -> base &&
2799
- dbg_stubs -> entries_count > 0 ) {
2800
- target = curr ;
2801
- break ;
2802
- }
2803
- }
2804
- } else
2805
- dbg_stubs = & (target_to_esp_xtensa (target )-> dbg_stubs );
2806
- old_state = target -> state ;
2807
- if (dbg_stubs -> entries_count < 1 || dbg_stubs -> desc .data_alloc == 0 ) {
2817
+ struct target * run_target = target ;
2818
+ /* connect and halt target, debug stubs info will be read if this is the first time
2819
+ *target is halted */
2820
+ res = esp32_apptrace_connect_targets (& s_at_cmd_ctx , true, false);
2821
+ if (res != ERROR_OK ) {
2822
+ LOG_ERROR ("Failed to connect to targets (%d)!" , res );
2823
+ esp_gcov_cmd_cleanup (& s_at_cmd_ctx );
2824
+ return res ;
2825
+ }
2826
+ struct esp_dbg_stubs * dbg_stubs = get_stubs_from_target (& run_target );
2827
+ if (dbg_stubs == NULL || dbg_stubs -> entries_count < 1 ||
2828
+ dbg_stubs -> desc .data_alloc == 0 ) {
2808
2829
LOG_ERROR ("No dbg stubs found!" );
2830
+ esp_gcov_cmd_cleanup (& s_at_cmd_ctx );
2809
2831
return ERROR_FAIL ;
2810
2832
}
2811
2833
if (dbg_stubs -> entries_count < ESP_DBG_STUB_ENTRY_GCOV + 1 ) {
2812
2834
LOG_ERROR ("No GCOV stubs found!" );
2835
+ esp_gcov_cmd_cleanup (& s_at_cmd_ctx );
2813
2836
return ERROR_FAIL ;
2814
2837
}
2815
2838
func_addr = dbg_stubs -> entries [ESP_DBG_STUB_ENTRY_GCOV ];
2816
2839
LOG_DEBUG ("GCOV_FUNC = 0x%x" , func_addr );
2817
2840
if (func_addr == 0 ) {
2818
2841
LOG_ERROR ("GCOV stub not found!" );
2819
- return ERROR_FAIL ;
2820
- }
2821
- /* connect */
2822
- res = esp32_apptrace_connect_targets (& s_at_cmd_ctx , true, dump );
2823
- if (res != ERROR_OK ) {
2824
- LOG_ERROR ("Failed to connect to targets (%d)!" , res );
2825
2842
esp_gcov_cmd_cleanup (& s_at_cmd_ctx );
2826
- return res ;
2843
+ return ERROR_FAIL ;
2827
2844
}
2828
2845
memset (& run , 0 , sizeof (run ));
2829
2846
run .stack_size = 1024 ;
@@ -2833,7 +2850,8 @@ COMMAND_HANDLER(esp32_cmd_gcov)
2833
2850
run .on_board .min_stack_size = ESP_DBG_STUBS_STACK_MIN_SIZE ;
2834
2851
run .on_board .code_buf_addr = dbg_stubs -> desc .tramp_addr ;
2835
2852
run .on_board .code_buf_size = ESP_DBG_STUBS_CODE_BUF_SIZE ;
2836
- xtensa_run_onboard_func (target , & run , func_addr , 0 );
2853
+ /* this gunction works for SMP and non-SMP targets */
2854
+ esp_xtensa_smp_run_onboard_func (run_target , & run , func_addr , 0 );
2837
2855
LOG_DEBUG ("FUNC RET = 0x%x" , run .ret_code );
2838
2856
}
2839
2857
/* disconnect */
0 commit comments