1 /******************************************************************************
3 * Module Name: dbhistry - debugger HISTORY command
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
50 #define _COMPONENT ACPI_CA_DEBUGGER
51 ACPI_MODULE_NAME ("dbhistry")
54 #define HI_NO_HISTORY 0
55 #define HI_RECORD_HISTORY 1
56 #define HISTORY_SIZE 40
59 typedef struct HistoryInfo
67 static HISTORY_INFO AcpiGbl_HistoryBuffer[HISTORY_SIZE];
68 static UINT16 AcpiGbl_LoHistory = 0;
69 static UINT16 AcpiGbl_NumHistory = 0;
70 static UINT16 AcpiGbl_NextHistoryIndex = 0;
71 UINT32 AcpiGbl_NextCmdNum = 1;
74 /*******************************************************************************
76 * FUNCTION: AcpiDbAddToHistory
78 * PARAMETERS: CommandLine - Command to add
82 * DESCRIPTION: Add a command line to the history buffer.
84 ******************************************************************************/
93 /* Put command into the next available slot */
95 CmdLen = (UINT16) ACPI_STRLEN (CommandLine);
101 if (AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command != NULL)
103 BufferLen = (UINT16) ACPI_STRLEN (
104 AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command);
105 if (CmdLen > BufferLen)
107 AcpiOsFree (AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].
109 AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command =
110 AcpiOsAllocate (CmdLen + 1);
115 AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command =
116 AcpiOsAllocate (CmdLen + 1);
119 ACPI_STRCPY (AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command,
122 AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].CmdNum =
127 if ((AcpiGbl_NumHistory == HISTORY_SIZE) &&
128 (AcpiGbl_NextHistoryIndex == AcpiGbl_LoHistory))
131 if (AcpiGbl_LoHistory >= HISTORY_SIZE)
133 AcpiGbl_LoHistory = 0;
137 AcpiGbl_NextHistoryIndex++;
138 if (AcpiGbl_NextHistoryIndex >= HISTORY_SIZE)
140 AcpiGbl_NextHistoryIndex = 0;
143 AcpiGbl_NextCmdNum++;
144 if (AcpiGbl_NumHistory < HISTORY_SIZE)
146 AcpiGbl_NumHistory++;
151 /*******************************************************************************
153 * FUNCTION: AcpiDbDisplayHistory
159 * DESCRIPTION: Display the contents of the history buffer
161 ******************************************************************************/
164 AcpiDbDisplayHistory (
171 HistoryIndex = AcpiGbl_LoHistory;
173 /* Dump entire history buffer */
175 for (i = 0; i < AcpiGbl_NumHistory; i++)
177 if (AcpiGbl_HistoryBuffer[HistoryIndex].Command)
179 AcpiOsPrintf ("%3ld %s\n",
180 AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum,
181 AcpiGbl_HistoryBuffer[HistoryIndex].Command);
185 if (HistoryIndex >= HISTORY_SIZE)
193 /*******************************************************************************
195 * FUNCTION: AcpiDbGetFromHistory
197 * PARAMETERS: CommandNumArg - String containing the number of the
198 * command to be retrieved
200 * RETURN: Pointer to the retrieved command. Null on error.
202 * DESCRIPTION: Get a command from the history buffer
204 ******************************************************************************/
207 AcpiDbGetFromHistory (
213 if (CommandNumArg == NULL)
215 CmdNum = AcpiGbl_NextCmdNum - 1;
220 CmdNum = ACPI_STRTOUL (CommandNumArg, NULL, 0);
223 return (AcpiDbGetHistoryByIndex (CmdNum));
227 /*******************************************************************************
229 * FUNCTION: AcpiDbGetHistoryByIndex
231 * PARAMETERS: CmdNum - Index of the desired history entry.
232 * Values are 0...(AcpiGbl_NextCmdNum - 1)
234 * RETURN: Pointer to the retrieved command. Null on error.
236 * DESCRIPTION: Get a command from the history buffer
238 ******************************************************************************/
241 AcpiDbGetHistoryByIndex (
248 /* Search history buffer */
250 HistoryIndex = AcpiGbl_LoHistory;
251 for (i = 0; i < AcpiGbl_NumHistory; i++)
253 if (AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum == CmdNum)
255 /* Found the command, return it */
257 return (AcpiGbl_HistoryBuffer[HistoryIndex].Command);
260 /* History buffer is circular */
263 if (HistoryIndex >= HISTORY_SIZE)
269 AcpiOsPrintf ("Invalid history number: %u\n", HistoryIndex);
273 #endif /* ACPI_DEBUGGER */