^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: dbhistry - debugger HISTORY command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "acdebug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define _COMPONENT ACPI_CA_DEBUGGER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) ACPI_MODULE_NAME("dbhistry")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define HI_NO_HISTORY 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define HI_RECORD_HISTORY 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define HISTORY_SIZE 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) typedef struct history_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) char *command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) u32 cmd_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) } HISTORY_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static HISTORY_INFO acpi_gbl_history_buffer[HISTORY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static u16 acpi_gbl_lo_history = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static u16 acpi_gbl_num_history = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static u16 acpi_gbl_next_history_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * FUNCTION: acpi_db_add_to_history
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * PARAMETERS: command_line - Command to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * DESCRIPTION: Add a command line to the history buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) void acpi_db_add_to_history(char *command_line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u16 cmd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u16 buffer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* Put command into the next available slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) cmd_len = (u16)strlen(command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (!cmd_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (acpi_gbl_history_buffer[acpi_gbl_next_history_index].command !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) buffer_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) (u16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) strlen(acpi_gbl_history_buffer[acpi_gbl_next_history_index].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (cmd_len > buffer_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) acpi_os_free(acpi_gbl_history_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) [acpi_gbl_next_history_index].command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) acpi_gbl_history_buffer[acpi_gbl_next_history_index].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) command = acpi_os_allocate(cmd_len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) acpi_gbl_history_buffer[acpi_gbl_next_history_index].command =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) acpi_os_allocate(cmd_len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) strcpy(acpi_gbl_history_buffer[acpi_gbl_next_history_index].command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) acpi_gbl_history_buffer[acpi_gbl_next_history_index].cmd_num =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) acpi_gbl_next_cmd_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* Adjust indexes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if ((acpi_gbl_num_history == HISTORY_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) (acpi_gbl_next_history_index == acpi_gbl_lo_history)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) acpi_gbl_lo_history++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (acpi_gbl_lo_history >= HISTORY_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) acpi_gbl_lo_history = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) acpi_gbl_next_history_index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (acpi_gbl_next_history_index >= HISTORY_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) acpi_gbl_next_history_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) acpi_gbl_next_cmd_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (acpi_gbl_num_history < HISTORY_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) acpi_gbl_num_history++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * FUNCTION: acpi_db_display_history
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * PARAMETERS: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * RETURN: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * DESCRIPTION: Display the contents of the history buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) void acpi_db_display_history(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) u16 history_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) history_index = acpi_gbl_lo_history;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* Dump entire history buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) for (i = 0; i < acpi_gbl_num_history; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (acpi_gbl_history_buffer[history_index].command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) acpi_os_printf("%3u %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) acpi_gbl_history_buffer[history_index].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) cmd_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) acpi_gbl_history_buffer[history_index].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) history_index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (history_index >= HISTORY_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) history_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * FUNCTION: acpi_db_get_from_history
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * PARAMETERS: command_num_arg - String containing the number of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * command to be retrieved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * RETURN: Pointer to the retrieved command. Null on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * DESCRIPTION: Get a command from the history buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) char *acpi_db_get_from_history(char *command_num_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u32 cmd_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (command_num_arg == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) cmd_num = acpi_gbl_next_cmd_num - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) cmd_num = strtoul(command_num_arg, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return (acpi_db_get_history_by_index(cmd_num));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * FUNCTION: acpi_db_get_history_by_index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * PARAMETERS: cmd_num - Index of the desired history entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Values are 0...(acpi_gbl_next_cmd_num - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * RETURN: Pointer to the retrieved command. Null on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * DESCRIPTION: Get a command from the history buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) char *acpi_db_get_history_by_index(u32 cmd_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) u16 history_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* Search history buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) history_index = acpi_gbl_lo_history;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) for (i = 0; i < acpi_gbl_num_history; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (acpi_gbl_history_buffer[history_index].cmd_num == cmd_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* Found the command, return it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return (acpi_gbl_history_buffer[history_index].command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* History buffer is circular */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) history_index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (history_index >= HISTORY_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) history_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) acpi_os_printf("Invalid history number: %u\n", history_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return (NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }