Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: dbhistry - debugger HISTORY command
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acdebug.h"
0013 
0014 #define _COMPONENT          ACPI_CA_DEBUGGER
0015 ACPI_MODULE_NAME("dbhistry")
0016 
0017 #define HI_NO_HISTORY       0
0018 #define HI_RECORD_HISTORY   1
0019 #define HISTORY_SIZE        40
0020 typedef struct history_info {
0021     char *command;
0022     u32 cmd_num;
0023 
0024 } HISTORY_INFO;
0025 
0026 static HISTORY_INFO acpi_gbl_history_buffer[HISTORY_SIZE];
0027 static u16 acpi_gbl_lo_history = 0;
0028 static u16 acpi_gbl_num_history = 0;
0029 static u16 acpi_gbl_next_history_index = 0;
0030 
0031 /*******************************************************************************
0032  *
0033  * FUNCTION:    acpi_db_add_to_history
0034  *
0035  * PARAMETERS:  command_line    - Command to add
0036  *
0037  * RETURN:      None
0038  *
0039  * DESCRIPTION: Add a command line to the history buffer.
0040  *
0041  ******************************************************************************/
0042 
0043 void acpi_db_add_to_history(char *command_line)
0044 {
0045     u16 cmd_len;
0046     u16 buffer_len;
0047 
0048     /* Put command into the next available slot */
0049 
0050     cmd_len = (u16)strlen(command_line);
0051     if (!cmd_len) {
0052         return;
0053     }
0054 
0055     if (acpi_gbl_history_buffer[acpi_gbl_next_history_index].command !=
0056         NULL) {
0057         buffer_len =
0058             (u16)
0059             strlen(acpi_gbl_history_buffer[acpi_gbl_next_history_index].
0060                command);
0061 
0062         if (cmd_len > buffer_len) {
0063             acpi_os_free(acpi_gbl_history_buffer
0064                      [acpi_gbl_next_history_index].command);
0065             acpi_gbl_history_buffer[acpi_gbl_next_history_index].
0066                 command = acpi_os_allocate(cmd_len + 1);
0067         }
0068     } else {
0069         acpi_gbl_history_buffer[acpi_gbl_next_history_index].command =
0070             acpi_os_allocate(cmd_len + 1);
0071     }
0072 
0073     strcpy(acpi_gbl_history_buffer[acpi_gbl_next_history_index].command,
0074            command_line);
0075 
0076     acpi_gbl_history_buffer[acpi_gbl_next_history_index].cmd_num =
0077         acpi_gbl_next_cmd_num;
0078 
0079     /* Adjust indexes */
0080 
0081     if ((acpi_gbl_num_history == HISTORY_SIZE) &&
0082         (acpi_gbl_next_history_index == acpi_gbl_lo_history)) {
0083         acpi_gbl_lo_history++;
0084         if (acpi_gbl_lo_history >= HISTORY_SIZE) {
0085             acpi_gbl_lo_history = 0;
0086         }
0087     }
0088 
0089     acpi_gbl_next_history_index++;
0090     if (acpi_gbl_next_history_index >= HISTORY_SIZE) {
0091         acpi_gbl_next_history_index = 0;
0092     }
0093 
0094     acpi_gbl_next_cmd_num++;
0095     if (acpi_gbl_num_history < HISTORY_SIZE) {
0096         acpi_gbl_num_history++;
0097     }
0098 }
0099 
0100 /*******************************************************************************
0101  *
0102  * FUNCTION:    acpi_db_display_history
0103  *
0104  * PARAMETERS:  None
0105  *
0106  * RETURN:      None
0107  *
0108  * DESCRIPTION: Display the contents of the history buffer
0109  *
0110  ******************************************************************************/
0111 
0112 void acpi_db_display_history(void)
0113 {
0114     u32 i;
0115     u16 history_index;
0116 
0117     history_index = acpi_gbl_lo_history;
0118 
0119     /* Dump entire history buffer */
0120 
0121     for (i = 0; i < acpi_gbl_num_history; i++) {
0122         if (acpi_gbl_history_buffer[history_index].command) {
0123             acpi_os_printf("%3u %s\n",
0124                        acpi_gbl_history_buffer[history_index].
0125                        cmd_num,
0126                        acpi_gbl_history_buffer[history_index].
0127                        command);
0128         }
0129 
0130         history_index++;
0131         if (history_index >= HISTORY_SIZE) {
0132             history_index = 0;
0133         }
0134     }
0135 }
0136 
0137 /*******************************************************************************
0138  *
0139  * FUNCTION:    acpi_db_get_from_history
0140  *
0141  * PARAMETERS:  command_num_arg         - String containing the number of the
0142  *                                        command to be retrieved
0143  *
0144  * RETURN:      Pointer to the retrieved command. Null on error.
0145  *
0146  * DESCRIPTION: Get a command from the history buffer
0147  *
0148  ******************************************************************************/
0149 
0150 char *acpi_db_get_from_history(char *command_num_arg)
0151 {
0152     u32 cmd_num;
0153 
0154     if (command_num_arg == NULL) {
0155         cmd_num = acpi_gbl_next_cmd_num - 1;
0156     }
0157 
0158     else {
0159         cmd_num = strtoul(command_num_arg, NULL, 0);
0160     }
0161 
0162     return (acpi_db_get_history_by_index(cmd_num));
0163 }
0164 
0165 /*******************************************************************************
0166  *
0167  * FUNCTION:    acpi_db_get_history_by_index
0168  *
0169  * PARAMETERS:  cmd_num             - Index of the desired history entry.
0170  *                                    Values are 0...(acpi_gbl_next_cmd_num - 1)
0171  *
0172  * RETURN:      Pointer to the retrieved command. Null on error.
0173  *
0174  * DESCRIPTION: Get a command from the history buffer
0175  *
0176  ******************************************************************************/
0177 
0178 char *acpi_db_get_history_by_index(u32 cmd_num)
0179 {
0180     u32 i;
0181     u16 history_index;
0182 
0183     /* Search history buffer */
0184 
0185     history_index = acpi_gbl_lo_history;
0186     for (i = 0; i < acpi_gbl_num_history; i++) {
0187         if (acpi_gbl_history_buffer[history_index].cmd_num == cmd_num) {
0188 
0189             /* Found the command, return it */
0190 
0191             return (acpi_gbl_history_buffer[history_index].command);
0192         }
0193 
0194         /* History buffer is circular */
0195 
0196         history_index++;
0197         if (history_index >= HISTORY_SIZE) {
0198             history_index = 0;
0199         }
0200     }
0201 
0202     acpi_os_printf("Invalid history number: %u\n", history_index);
0203     return (NULL);
0204 }