@@ -57,7 +57,7 @@ static int os_alloc(struct target *target, const struct rtos_type *ostype)
5757 struct rtos * os = target -> rtos = calloc (1 , sizeof (struct rtos ));
5858
5959 if (!os )
60- return JIM_ERR ;
60+ return ERROR_FAIL ;
6161
6262 os -> type = ostype ;
6363 os -> current_threadid = -1 ;
@@ -69,7 +69,7 @@ static int os_alloc(struct target *target, const struct rtos_type *ostype)
6969 os -> gdb_thread_packet = rtos_thread_packet ;
7070 os -> gdb_target_for_threadid = rtos_target_for_threadid ;
7171
72- return JIM_OK ;
72+ return ERROR_OK ;
7373}
7474
7575static void os_free (struct target * target )
@@ -86,38 +86,26 @@ static void os_free(struct target *target)
8686static int os_alloc_create (struct target * target , const struct rtos_type * ostype )
8787{
8888 int ret = os_alloc (target , ostype );
89+ if (ret != ERROR_OK )
90+ return ret ;
8991
90- if (ret == JIM_OK ) {
91- ret = target -> rtos -> type -> create (target );
92- if (ret != JIM_OK )
93- os_free (target );
94- }
92+ ret = target -> rtos -> type -> create (target );
93+ if (ret != ERROR_OK )
94+ os_free (target );
9595
9696 return ret ;
9797}
9898
99- int rtos_create (struct jim_getopt_info * goi , struct target * target )
99+ int rtos_create (struct command_invocation * cmd , struct target * target ,
100+ const char * rtos_name )
100101{
101- int x ;
102- const char * cp ;
103- Jim_Obj * res ;
104- int e ;
105-
106- if (!goi -> is_configure && goi -> argc != 0 ) {
107- Jim_WrongNumArgs (goi -> interp , goi -> argc , goi -> argv , "NO PARAMS" );
108- return JIM_ERR ;
109- }
110-
111102 os_free (target );
103+ target -> rtos_auto_detect = false;
112104
113- e = jim_getopt_string (goi , & cp , NULL );
114- if (e != JIM_OK )
115- return e ;
116-
117- if (strcmp (cp , "none" ) == 0 )
118- return JIM_OK ;
105+ if (strcmp (rtos_name , "none" ) == 0 )
106+ return ERROR_OK ;
119107
120- if (strcmp (cp , "auto" ) == 0 ) {
108+ if (strcmp (rtos_name , "auto" ) == 0 ) {
121109 /* Auto detect tries to look up all symbols for each RTOS,
122110 * and runs the RTOS driver's _detect() function when GDB
123111 * finds all symbols for any RTOS. See rtos_qsymbol(). */
@@ -128,17 +116,29 @@ int rtos_create(struct jim_getopt_info *goi, struct target *target)
128116 return os_alloc (target , rtos_types [0 ]);
129117 }
130118
131- for (x = 0 ; rtos_types [x ]; x ++ )
132- if (strcmp (cp , rtos_types [x ]-> name ) == 0 )
119+ for (int x = 0 ; rtos_types [x ]; x ++ )
120+ if (strcmp (rtos_name , rtos_types [x ]-> name ) == 0 )
133121 return os_alloc_create (target , rtos_types [x ]);
134122
135- Jim_SetResultFormatted (goi -> interp , "Unknown RTOS type %s, try one of: " , cp );
136- res = Jim_GetResult (goi -> interp );
137- for (x = 0 ; rtos_types [x ]; x ++ )
138- Jim_AppendStrings (goi -> interp , res , rtos_types [x ]-> name , ", " , NULL );
139- Jim_AppendStrings (goi -> interp , res , ", auto or none" , NULL );
123+ char * all = NULL ;
124+ for (int x = 0 ; rtos_types [x ]; x ++ ) {
125+ char * prev = all ;
126+ if (all )
127+ all = alloc_printf ("%s, %s" , all , rtos_types [x ]-> name );
128+ else
129+ all = alloc_printf ("%s" , rtos_types [x ]-> name );
130+ free (prev );
131+ if (!all ) {
132+ LOG_ERROR ("Out of memory" );
133+ return ERROR_FAIL ;
134+ }
135+ }
136+
137+ command_print (cmd , "Unknown RTOS type %s, try one of: %s, auto or none" ,
138+ rtos_name , all );
139+ free (all );
140140
141- return JIM_ERR ;
141+ return ERROR_COMMAND_ARGUMENT_INVALID ;
142142}
143143
144144void rtos_destroy (struct target * target )
0 commit comments