adapter: list supported transports beside adapter name
authorAntonio Borneo <borneo.antonio@gmail.com>
Sat, 4 Jan 2025 17:41:41 +0000 (18:41 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Thu, 1 May 2025 15:25:31 +0000 (15:25 +0000)
Modify the command 'adapter list' to output the list of transports
supported by each adapter driver.
Drop the line number, as there is no real interest on it.
Format the output as a TCL dictionary indexed by the adapter name
and containing the transports in a TCL list. E.g:
dummy          { jtag }
ftdi           { jtag swd }

This format is easily handled by TCL scripts, e.g.:
dict get [adapter list] ftdi

Document the command output.

Change-Id: I69f73b71da2f1756866a63bc2c0ba33459a29063
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8691
Tested-by: jenkins
doc/openocd.texi
src/jtag/adapter.c

index 32a2895ecf19e3816841783a6c2c0eb1eb541895..d85812824fc0bc4107f4c87894b5b41b3f1928cd 100644 (file)
@@ -2414,6 +2414,17 @@ target.
 @deffn {Command} {adapter list}
 List the debug adapter drivers that have been built into
 the running copy of OpenOCD.
+
+The output is formatted as a Tcl dictionary indexed by the adapter name
+and containing the transports in a Tcl list.
+@example
+dummy  @{ jtag @}
+ftdi   @{ jtag swd @}
+@end example
+This format is easily handled by Tcl scripts:
+@example
+dict get [adapter list] ftdi
+@end example
 @end deffn
 
 @anchor{adapter gpio}
index 0bdfe7b13402a9d4a69d2b67a758e93bd77a60c3..694721746115b3099b07ed960c65e96055dc8743 100644 (file)
@@ -393,9 +393,21 @@ COMMAND_HANDLER(handle_adapter_name)
 
 COMMAND_HANDLER(dump_adapter_driver_list)
 {
+       int max_len = 0;
+       for (unsigned int i = 0; adapter_drivers[i]; i++) {
+               int len = strlen(adapter_drivers[i]->name);
+               if (max_len < len)
+                       max_len = len;
+       }
+
        for (unsigned int i = 0; adapter_drivers[i]; i++) {
                const char *name = adapter_drivers[i]->name;
-               command_print(CMD, "%u: %s", i + 1, name);
+               const char * const *transports = adapter_drivers[i]->transports;
+
+               command_print_sameline(CMD, "%-*s {", max_len, name);
+               for (unsigned int j = 0; transports[j]; j++)
+                       command_print_sameline(CMD, " %s", transports[j]);
+               command_print(CMD, " }");
        }
 
        return ERROR_OK;