1 /******************************************************************************
3 * Module Name: dbhistry - debugger HISTORY command
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acdebug.h>
51 #define _COMPONENT ACPI_CA_DEBUGGER
52 ACPI_MODULE_NAME ("dbhistry")
55 #define HI_NO_HISTORY 0
56 #define HI_RECORD_HISTORY 1
57 #define HISTORY_SIZE 20
60 typedef struct HistoryInfo
68 static HISTORY_INFO AcpiGbl_HistoryBuffer[HISTORY_SIZE];
69 static UINT16 AcpiGbl_LoHistory = 0;
70 static UINT16 AcpiGbl_NumHistory = 0;
71 static UINT16 AcpiGbl_NextHistoryIndex = 0;
72 static UINT32 AcpiGbl_NextCmdNum = 1;
75 /*******************************************************************************
77 * FUNCTION: AcpiDbAddToHistory
79 * PARAMETERS: CommandLine - Command to add
83 * DESCRIPTION: Add a command line to the history buffer.
85 ******************************************************************************/
92 /* Put command into the next available slot */
94 ACPI_STRCPY (AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command,
97 AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].CmdNum = AcpiGbl_NextCmdNum;
101 if ((AcpiGbl_NumHistory == HISTORY_SIZE) &&
102 (AcpiGbl_NextHistoryIndex == AcpiGbl_LoHistory))
105 if (AcpiGbl_LoHistory >= HISTORY_SIZE)
107 AcpiGbl_LoHistory = 0;
111 AcpiGbl_NextHistoryIndex++;
112 if (AcpiGbl_NextHistoryIndex >= HISTORY_SIZE)
114 AcpiGbl_NextHistoryIndex = 0;
117 AcpiGbl_NextCmdNum++;
118 if (AcpiGbl_NumHistory < HISTORY_SIZE)
120 AcpiGbl_NumHistory++;
125 /*******************************************************************************
127 * FUNCTION: AcpiDbDisplayHistory
133 * DESCRIPTION: Display the contents of the history buffer
135 ******************************************************************************/
138 AcpiDbDisplayHistory (
145 HistoryIndex = AcpiGbl_LoHistory;
147 /* Dump entire history buffer */
149 for (i = 0; i < AcpiGbl_NumHistory; i++)
151 AcpiOsPrintf ("%ld %s\n", AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum,
152 AcpiGbl_HistoryBuffer[HistoryIndex].Command);
155 if (HistoryIndex >= HISTORY_SIZE)
163 /*******************************************************************************
165 * FUNCTION: AcpiDbGetFromHistory
167 * PARAMETERS: CommandNumArg - String containing the number of the
168 * command to be retrieved
170 * RETURN: Pointer to the retrieved command. Null on error.
172 * DESCRIPTION: Get a command from the history buffer
174 ******************************************************************************/
177 AcpiDbGetFromHistory (
185 if (CommandNumArg == NULL)
187 CmdNum = AcpiGbl_NextCmdNum - 1;
192 CmdNum = ACPI_STRTOUL (CommandNumArg, NULL, 0);
195 /* Search history buffer */
197 HistoryIndex = AcpiGbl_LoHistory;
198 for (i = 0; i < AcpiGbl_NumHistory; i++)
200 if (AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum == CmdNum)
202 /* Found the commnad, return it */
204 return (AcpiGbl_HistoryBuffer[HistoryIndex].Command);
209 if (HistoryIndex >= HISTORY_SIZE)
215 AcpiOsPrintf ("Invalid history number: %u\n", HistoryIndex);
219 #endif /* ACPI_DEBUGGER */