1767af88aa617288e584afcfed055f7755e408542Jim Ingham//===-- CommandObjectSource.cpp ---------------------------------*- C++ -*-===// 2767af88aa617288e584afcfed055f7755e408542Jim Ingham// 3767af88aa617288e584afcfed055f7755e408542Jim Ingham// The LLVM Compiler Infrastructure 4767af88aa617288e584afcfed055f7755e408542Jim Ingham// 5767af88aa617288e584afcfed055f7755e408542Jim Ingham// This file is distributed under the University of Illinois Open Source 6767af88aa617288e584afcfed055f7755e408542Jim Ingham// License. See LICENSE.TXT for details. 7767af88aa617288e584afcfed055f7755e408542Jim Ingham// 8767af88aa617288e584afcfed055f7755e408542Jim Ingham//===----------------------------------------------------------------------===// 9767af88aa617288e584afcfed055f7755e408542Jim Ingham 10d891f9b872103235cfd2ed452c6f14a4394d9b3aDaniel Malea#include "lldb/lldb-python.h" 11d891f9b872103235cfd2ed452c6f14a4394d9b3aDaniel Malea 12767af88aa617288e584afcfed055f7755e408542Jim Ingham#include "CommandObjectCommands.h" 13767af88aa617288e584afcfed055f7755e408542Jim Ingham 14767af88aa617288e584afcfed055f7755e408542Jim Ingham// C Includes 15767af88aa617288e584afcfed055f7755e408542Jim Ingham// C++ Includes 16767af88aa617288e584afcfed055f7755e408542Jim Ingham// Other libraries and framework includes 1740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton#include "llvm/ADT/StringRef.h" 1840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 19767af88aa617288e584afcfed055f7755e408542Jim Ingham// Project includes 20767af88aa617288e584afcfed055f7755e408542Jim Ingham#include "lldb/Core/Debugger.h" 21d12aeab33bab559e138307f599077da3918a3238Greg Clayton#include "lldb/Core/InputReader.h" 22c2a2825d787be5459fc55264e55b6020ff62f68aEnrico Granata#include "lldb/Core/InputReaderEZ.h" 23c2a2825d787be5459fc55264e55b6020ff62f68aEnrico Granata#include "lldb/Core/StringList.h" 24d12aeab33bab559e138307f599077da3918a3238Greg Clayton#include "lldb/Interpreter/Args.h" 25b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata#include "lldb/Interpreter/CommandHistory.h" 26767af88aa617288e584afcfed055f7755e408542Jim Ingham#include "lldb/Interpreter/CommandInterpreter.h" 27d12aeab33bab559e138307f599077da3918a3238Greg Clayton#include "lldb/Interpreter/CommandObjectRegexCommand.h" 28767af88aa617288e584afcfed055f7755e408542Jim Ingham#include "lldb/Interpreter/CommandReturnObject.h" 296fefc3a3915bcaf899b9179c43b1b7b2f693b3adEnrico Granata#include "lldb/Interpreter/OptionValueBoolean.h" 30b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata#include "lldb/Interpreter/OptionValueUInt64.h" 31767af88aa617288e584afcfed055f7755e408542Jim Ingham#include "lldb/Interpreter/Options.h" 32e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata#include "lldb/Interpreter/ScriptInterpreter.h" 33e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata#include "lldb/Interpreter/ScriptInterpreterPython.h" 34767af88aa617288e584afcfed055f7755e408542Jim Ingham 35767af88aa617288e584afcfed055f7755e408542Jim Inghamusing namespace lldb; 36767af88aa617288e584afcfed055f7755e408542Jim Inghamusing namespace lldb_private; 37767af88aa617288e584afcfed055f7755e408542Jim Ingham 38767af88aa617288e584afcfed055f7755e408542Jim Ingham//------------------------------------------------------------------------- 39767af88aa617288e584afcfed055f7755e408542Jim Ingham// CommandObjectCommandsSource 40767af88aa617288e584afcfed055f7755e408542Jim Ingham//------------------------------------------------------------------------- 41767af88aa617288e584afcfed055f7755e408542Jim Ingham 42da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsHistory : public CommandObjectParsed 436247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham{ 44da26bd203cbb104291b39891febf7481794f205fJim Inghampublic: 45da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectCommandsHistory(CommandInterpreter &interpreter) : 46da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectParsed (interpreter, 47da26bd203cbb104291b39891febf7481794f205fJim Ingham "command history", 48da26bd203cbb104291b39891febf7481794f205fJim Ingham "Dump the history of commands in this session.", 49da26bd203cbb104291b39891febf7481794f205fJim Ingham NULL), 50da26bd203cbb104291b39891febf7481794f205fJim Ingham m_options (interpreter) 51da26bd203cbb104291b39891febf7481794f205fJim Ingham { 52da26bd203cbb104291b39891febf7481794f205fJim Ingham } 53da26bd203cbb104291b39891febf7481794f205fJim Ingham 54da26bd203cbb104291b39891febf7481794f205fJim Ingham ~CommandObjectCommandsHistory () {} 55da26bd203cbb104291b39891febf7481794f205fJim Ingham 56da26bd203cbb104291b39891febf7481794f205fJim Ingham virtual Options * 57da26bd203cbb104291b39891febf7481794f205fJim Ingham GetOptions () 58da26bd203cbb104291b39891febf7481794f205fJim Ingham { 59da26bd203cbb104291b39891febf7481794f205fJim Ingham return &m_options; 60da26bd203cbb104291b39891febf7481794f205fJim Ingham } 61da26bd203cbb104291b39891febf7481794f205fJim Ingham 62da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 636247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 646247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham class CommandOptions : public Options 656247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham { 666247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham public: 676247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 686247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham CommandOptions (CommandInterpreter &interpreter) : 69b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata Options (interpreter), 70b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata m_start_idx(0), 71b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata m_stop_idx(0), 72b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata m_count(0), 733f0cc74e68663aff8c0262dee99fdf2c1250fb7bEnrico Granata m_clear(false) 746247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham { 756247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham } 766247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 776247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham virtual 786247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham ~CommandOptions (){} 796247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 806247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham virtual Error 816247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham SetOptionValue (uint32_t option_idx, const char *option_arg) 826247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham { 836247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham Error error; 846475c42148a8ea1ca86e5db465db7eca742d897dGreg Clayton const int short_option = m_getopt_table[option_idx].val; 856247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 866247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham switch (short_option) 876247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham { 886247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham case 'c': 89b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata error = m_count.SetValueFromCString(option_arg,eVarSetOperationAssign); 90b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata break; 91b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata case 's': 92b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata if (option_arg && strcmp("end", option_arg) == 0) 93b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 94b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata m_start_idx.SetCurrentValue(UINT64_MAX); 95b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata m_start_idx.SetOptionWasSet(); 96b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 97b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else 98b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata error = m_start_idx.SetValueFromCString(option_arg,eVarSetOperationAssign); 996247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham break; 1006247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham case 'e': 101b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata error = m_stop_idx.SetValueFromCString(option_arg,eVarSetOperationAssign); 1026247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham break; 1033f0cc74e68663aff8c0262dee99fdf2c1250fb7bEnrico Granata case 'C': 1043f0cc74e68663aff8c0262dee99fdf2c1250fb7bEnrico Granata m_clear.SetCurrentValue(true); 1053f0cc74e68663aff8c0262dee99fdf2c1250fb7bEnrico Granata m_clear.SetOptionWasSet(); 1066247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham break; 1076247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham default: 1089c236733d43e6250c8a5671a438f4a2afeb9c0b2Greg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 1096247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham break; 1106247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham } 1116247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 1126247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham return error; 1136247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham } 1146247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 1156247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham void 1166247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham OptionParsingStarting () 1176247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham { 118b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata m_start_idx.Clear(); 119b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata m_stop_idx.Clear(); 120b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata m_count.Clear(); 1213f0cc74e68663aff8c0262dee99fdf2c1250fb7bEnrico Granata m_clear.Clear(); 1226247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham } 1236247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 1246247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham const OptionDefinition* 1256247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham GetDefinitions () 1266247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham { 1276247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham return g_option_table; 1286247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham } 1296247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 1306247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham // Options table: Required for subclasses of Options. 1316247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 1326247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham static OptionDefinition g_option_table[]; 1336247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 1346247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham // Instance variables to hold the values for command options. 1356247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 136b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata OptionValueUInt64 m_start_idx; 137b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata OptionValueUInt64 m_stop_idx; 138b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata OptionValueUInt64 m_count; 1393f0cc74e68663aff8c0262dee99fdf2c1250fb7bEnrico Granata OptionValueBoolean m_clear; 1406247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham }; 1416247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 1426247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham bool 143da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (Args& command, CommandReturnObject &result) 1446247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham { 1453f0cc74e68663aff8c0262dee99fdf2c1250fb7bEnrico Granata if (m_options.m_clear.GetCurrentValue() && m_options.m_clear.OptionWasSet()) 146b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 147b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata m_interpreter.GetCommandHistory().Clear(); 148b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult); 149b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 150b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else 151b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 152b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata if (m_options.m_start_idx.OptionWasSet() && m_options.m_stop_idx.OptionWasSet() && m_options.m_count.OptionWasSet()) 153b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 154b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata result.AppendError("--count, --start-index and --end-index cannot be all specified in the same invocation"); 155b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata result.SetStatus(lldb::eReturnStatusFailed); 156b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 157b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else 158b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 159b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata std::pair<bool,uint64_t> start_idx = {m_options.m_start_idx.OptionWasSet(),m_options.m_start_idx.GetCurrentValue()}; 160b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata std::pair<bool,uint64_t> stop_idx = {m_options.m_stop_idx.OptionWasSet(),m_options.m_stop_idx.GetCurrentValue()}; 161b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata std::pair<bool,uint64_t> count = {m_options.m_count.OptionWasSet(),m_options.m_count.GetCurrentValue()}; 162b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata 163b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata const CommandHistory& history(m_interpreter.GetCommandHistory()); 164b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata 165b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata if (start_idx.first && start_idx.second == UINT64_MAX) 166b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 167b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata if (count.first) 168b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 169b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata start_idx.second = history.GetSize() - count.second; 170b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata stop_idx.second = history.GetSize() - 1; 171b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 172b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else if (stop_idx.first) 173b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 174b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata start_idx.second = stop_idx.second; 175b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata stop_idx.second = history.GetSize() - 1; 176b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 177b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else 178b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 179b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata start_idx.second = 0; 180b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata stop_idx.second = history.GetSize() - 1; 181b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 182b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 183b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else 184b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 185b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata if (!start_idx.first && !stop_idx.first && !count.first) 186b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 187b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata start_idx.second = 0; 188b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata stop_idx.second = history.GetSize() - 1; 189b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 190b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else if (start_idx.first) 191b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 192b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata if (count.first) 193b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 194b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata stop_idx.second = start_idx.second + count.second - 1; 195b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 196b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else if (!stop_idx.first) 197b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 198b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata stop_idx.second = history.GetSize() - 1; 199b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 200b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 201b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else if (stop_idx.first) 202b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 203b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata if (count.first) 204b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 205b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata if (stop_idx.second >= count.second) 206b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata start_idx.second = stop_idx.second - count.second + 1; 207b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else 208b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata start_idx.second = 0; 209b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 210b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 211b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata else /* if (count.first) */ 212b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata { 213b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata start_idx.second = 0; 214b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata stop_idx.second = count.second - 1; 215b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 216b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 217b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata history.Dump(result.GetOutputStream(), start_idx.second, stop_idx.second); 218b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 219b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata } 2206247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham return result.Succeeded(); 2216247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 2226247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham } 223da26bd203cbb104291b39891febf7481794f205fJim Ingham 224da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandOptions m_options; 2256247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham}; 2266247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 2276247dbee41ec51e9a082df7e86269c0f47f28160Jim InghamOptionDefinition 2286247dbee41ec51e9a082df7e86269c0f47f28160Jim InghamCommandObjectCommandsHistory::CommandOptions::g_option_table[] = 2296247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham{ 2306247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham{ LLDB_OPT_SET_1, false, "count", 'c', required_argument, NULL, 0, eArgTypeUnsignedInteger, "How many history commands to print."}, 231b1fb72761226817e7f687eca21cbe9c0a3ec4cf6Enrico Granata{ LLDB_OPT_SET_1, false, "start-index", 's', required_argument, NULL, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands (or end to mean tail mode)."}, 2326247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham{ LLDB_OPT_SET_1, false, "end-index", 'e', required_argument, NULL, 0, eArgTypeUnsignedInteger, "Index at which to stop printing history commands."}, 2333f0cc74e68663aff8c0262dee99fdf2c1250fb7bEnrico Granata{ LLDB_OPT_SET_2, false, "clear", 'C', no_argument, NULL, 0, eArgTypeBoolean, "Clears the current command history."}, 2346247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 2356247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham}; 2366247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 2376247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 2386247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham//------------------------------------------------------------------------- 2396247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham// CommandObjectCommandsSource 2406247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham//------------------------------------------------------------------------- 2416247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham 242da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsSource : public CommandObjectParsed 243767af88aa617288e584afcfed055f7755e408542Jim Ingham{ 244da26bd203cbb104291b39891febf7481794f205fJim Inghampublic: 245da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectCommandsSource(CommandInterpreter &interpreter) : 246da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectParsed (interpreter, 247da26bd203cbb104291b39891febf7481794f205fJim Ingham "command source", 248da26bd203cbb104291b39891febf7481794f205fJim Ingham "Read in debugger commands from the file <filename> and execute them.", 249da26bd203cbb104291b39891febf7481794f205fJim Ingham NULL), 250da26bd203cbb104291b39891febf7481794f205fJim Ingham m_options (interpreter) 251da26bd203cbb104291b39891febf7481794f205fJim Ingham { 252da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandArgumentEntry arg; 253da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandArgumentData file_arg; 254da26bd203cbb104291b39891febf7481794f205fJim Ingham 255da26bd203cbb104291b39891febf7481794f205fJim Ingham // Define the first (and only) variant of this arg. 256da26bd203cbb104291b39891febf7481794f205fJim Ingham file_arg.arg_type = eArgTypeFilename; 257da26bd203cbb104291b39891febf7481794f205fJim Ingham file_arg.arg_repetition = eArgRepeatPlain; 258da26bd203cbb104291b39891febf7481794f205fJim Ingham 259da26bd203cbb104291b39891febf7481794f205fJim Ingham // There is only one variant this argument could be; put it into the argument entry. 260da26bd203cbb104291b39891febf7481794f205fJim Ingham arg.push_back (file_arg); 261da26bd203cbb104291b39891febf7481794f205fJim Ingham 262da26bd203cbb104291b39891febf7481794f205fJim Ingham // Push the data for the first argument into the m_arguments vector. 263da26bd203cbb104291b39891febf7481794f205fJim Ingham m_arguments.push_back (arg); 264da26bd203cbb104291b39891febf7481794f205fJim Ingham } 265da26bd203cbb104291b39891febf7481794f205fJim Ingham 266da26bd203cbb104291b39891febf7481794f205fJim Ingham ~CommandObjectCommandsSource () {} 267da26bd203cbb104291b39891febf7481794f205fJim Ingham 268da26bd203cbb104291b39891febf7481794f205fJim Ingham virtual const char* 269da26bd203cbb104291b39891febf7481794f205fJim Ingham GetRepeatCommand (Args ¤t_command_args, uint32_t index) 270da26bd203cbb104291b39891febf7481794f205fJim Ingham { 271da26bd203cbb104291b39891febf7481794f205fJim Ingham return ""; 272da26bd203cbb104291b39891febf7481794f205fJim Ingham } 273da26bd203cbb104291b39891febf7481794f205fJim Ingham 27436da2aa6dc5ad9994b638ed09eb81c44cc05540bGreg Clayton virtual int 275da26bd203cbb104291b39891febf7481794f205fJim Ingham HandleArgumentCompletion (Args &input, 276da26bd203cbb104291b39891febf7481794f205fJim Ingham int &cursor_index, 277da26bd203cbb104291b39891febf7481794f205fJim Ingham int &cursor_char_position, 278da26bd203cbb104291b39891febf7481794f205fJim Ingham OptionElementVector &opt_element_vector, 279da26bd203cbb104291b39891febf7481794f205fJim Ingham int match_start_point, 280da26bd203cbb104291b39891febf7481794f205fJim Ingham int max_return_elements, 281da26bd203cbb104291b39891febf7481794f205fJim Ingham bool &word_complete, 282da26bd203cbb104291b39891febf7481794f205fJim Ingham StringList &matches) 283da26bd203cbb104291b39891febf7481794f205fJim Ingham { 284da26bd203cbb104291b39891febf7481794f205fJim Ingham std::string completion_str (input.GetArgumentAtIndex(cursor_index)); 285da26bd203cbb104291b39891febf7481794f205fJim Ingham completion_str.erase (cursor_char_position); 286da26bd203cbb104291b39891febf7481794f205fJim Ingham 287da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, 288da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandCompletions::eDiskFileCompletion, 289da26bd203cbb104291b39891febf7481794f205fJim Ingham completion_str.c_str(), 290da26bd203cbb104291b39891febf7481794f205fJim Ingham match_start_point, 291da26bd203cbb104291b39891febf7481794f205fJim Ingham max_return_elements, 292da26bd203cbb104291b39891febf7481794f205fJim Ingham NULL, 293da26bd203cbb104291b39891febf7481794f205fJim Ingham word_complete, 294da26bd203cbb104291b39891febf7481794f205fJim Ingham matches); 295da26bd203cbb104291b39891febf7481794f205fJim Ingham return matches.GetSize(); 296da26bd203cbb104291b39891febf7481794f205fJim Ingham } 297da26bd203cbb104291b39891febf7481794f205fJim Ingham 298da26bd203cbb104291b39891febf7481794f205fJim Ingham virtual Options * 299da26bd203cbb104291b39891febf7481794f205fJim Ingham GetOptions () 300da26bd203cbb104291b39891febf7481794f205fJim Ingham { 301da26bd203cbb104291b39891febf7481794f205fJim Ingham return &m_options; 302da26bd203cbb104291b39891febf7481794f205fJim Ingham } 303da26bd203cbb104291b39891febf7481794f205fJim Ingham 304da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 305949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 306949d5acde6684b5824a26034457410cdf3823dfeJim Ingham class CommandOptions : public Options 307949d5acde6684b5824a26034457410cdf3823dfeJim Ingham { 308949d5acde6684b5824a26034457410cdf3823dfeJim Ingham public: 309949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 310f15996eea072cdaa8a092f22d3a1212b3d95f0ecGreg Clayton CommandOptions (CommandInterpreter &interpreter) : 3116fefc3a3915bcaf899b9179c43b1b7b2f693b3adEnrico Granata Options (interpreter), 3126fefc3a3915bcaf899b9179c43b1b7b2f693b3adEnrico Granata m_stop_on_error (true) 313f15996eea072cdaa8a092f22d3a1212b3d95f0ecGreg Clayton { 314f15996eea072cdaa8a092f22d3a1212b3d95f0ecGreg Clayton } 315949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 316949d5acde6684b5824a26034457410cdf3823dfeJim Ingham virtual 317949d5acde6684b5824a26034457410cdf3823dfeJim Ingham ~CommandOptions (){} 318949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 319949d5acde6684b5824a26034457410cdf3823dfeJim Ingham virtual Error 320143fcc3a15425659b381502ed4e1e50a3e726f36Greg Clayton SetOptionValue (uint32_t option_idx, const char *option_arg) 321949d5acde6684b5824a26034457410cdf3823dfeJim Ingham { 322949d5acde6684b5824a26034457410cdf3823dfeJim Ingham Error error; 3236475c42148a8ea1ca86e5db465db7eca742d897dGreg Clayton const int short_option = m_getopt_table[option_idx].val; 324949d5acde6684b5824a26034457410cdf3823dfeJim Ingham bool success; 325949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 326949d5acde6684b5824a26034457410cdf3823dfeJim Ingham switch (short_option) 327949d5acde6684b5824a26034457410cdf3823dfeJim Ingham { 328949d5acde6684b5824a26034457410cdf3823dfeJim Ingham case 'e': 329688ad894166b915bf5fd4d7596fbf538358a6d3eEnrico Granata error = m_stop_on_error.SetValueFromCString(option_arg); 330949d5acde6684b5824a26034457410cdf3823dfeJim Ingham break; 331949d5acde6684b5824a26034457410cdf3823dfeJim Ingham case 'c': 332949d5acde6684b5824a26034457410cdf3823dfeJim Ingham m_stop_on_continue = Args::StringToBoolean(option_arg, true, &success); 333949d5acde6684b5824a26034457410cdf3823dfeJim Ingham if (!success) 3349c236733d43e6250c8a5671a438f4a2afeb9c0b2Greg Clayton error.SetErrorStringWithFormat("invalid value for stop-on-continue: %s", option_arg); 335949d5acde6684b5824a26034457410cdf3823dfeJim Ingham break; 336246621a2afb9848d96a1beea1d790f433fce6ed4Michael Sartain case 's': 337246621a2afb9848d96a1beea1d790f433fce6ed4Michael Sartain m_silent_run = Args::StringToBoolean(option_arg, true, &success); 338246621a2afb9848d96a1beea1d790f433fce6ed4Michael Sartain if (!success) 339246621a2afb9848d96a1beea1d790f433fce6ed4Michael Sartain error.SetErrorStringWithFormat("invalid value for silent-run: %s", option_arg); 340246621a2afb9848d96a1beea1d790f433fce6ed4Michael Sartain break; 341949d5acde6684b5824a26034457410cdf3823dfeJim Ingham default: 3429c236733d43e6250c8a5671a438f4a2afeb9c0b2Greg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 343949d5acde6684b5824a26034457410cdf3823dfeJim Ingham break; 344949d5acde6684b5824a26034457410cdf3823dfeJim Ingham } 345949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 346949d5acde6684b5824a26034457410cdf3823dfeJim Ingham return error; 347949d5acde6684b5824a26034457410cdf3823dfeJim Ingham } 348949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 349949d5acde6684b5824a26034457410cdf3823dfeJim Ingham void 350143fcc3a15425659b381502ed4e1e50a3e726f36Greg Clayton OptionParsingStarting () 351949d5acde6684b5824a26034457410cdf3823dfeJim Ingham { 3526fefc3a3915bcaf899b9179c43b1b7b2f693b3adEnrico Granata m_stop_on_error.Clear(); 353246621a2afb9848d96a1beea1d790f433fce6ed4Michael Sartain m_silent_run = false; 354949d5acde6684b5824a26034457410cdf3823dfeJim Ingham m_stop_on_continue = true; 355949d5acde6684b5824a26034457410cdf3823dfeJim Ingham } 356949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 357b344843f75ef893762c93fd0a22d2d45712ce74dGreg Clayton const OptionDefinition* 358949d5acde6684b5824a26034457410cdf3823dfeJim Ingham GetDefinitions () 359949d5acde6684b5824a26034457410cdf3823dfeJim Ingham { 360949d5acde6684b5824a26034457410cdf3823dfeJim Ingham return g_option_table; 361949d5acde6684b5824a26034457410cdf3823dfeJim Ingham } 362949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 363949d5acde6684b5824a26034457410cdf3823dfeJim Ingham // Options table: Required for subclasses of Options. 364949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 365b344843f75ef893762c93fd0a22d2d45712ce74dGreg Clayton static OptionDefinition g_option_table[]; 366949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 367949d5acde6684b5824a26034457410cdf3823dfeJim Ingham // Instance variables to hold the values for command options. 368949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 3696fefc3a3915bcaf899b9179c43b1b7b2f693b3adEnrico Granata OptionValueBoolean m_stop_on_error; 370246621a2afb9848d96a1beea1d790f433fce6ed4Michael Sartain bool m_silent_run; 371949d5acde6684b5824a26034457410cdf3823dfeJim Ingham bool m_stop_on_continue; 372949d5acde6684b5824a26034457410cdf3823dfeJim Ingham }; 373949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 374767af88aa617288e584afcfed055f7755e408542Jim Ingham bool 375da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute(Args& command, CommandReturnObject &result) 376767af88aa617288e584afcfed055f7755e408542Jim Ingham { 37736da2aa6dc5ad9994b638ed09eb81c44cc05540bGreg Clayton const size_t argc = command.GetArgumentCount(); 378767af88aa617288e584afcfed055f7755e408542Jim Ingham if (argc == 1) 379767af88aa617288e584afcfed055f7755e408542Jim Ingham { 380da26bd203cbb104291b39891febf7481794f205fJim Ingham const char *filename = command.GetArgumentAtIndex(0); 381767af88aa617288e584afcfed055f7755e408542Jim Ingham 382767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendMessageWithFormat ("Executing commands in '%s'.\n", filename); 383767af88aa617288e584afcfed055f7755e408542Jim Ingham 384a83ea887f6165d59cfeac1bbb96011f3b0568af8Johnny Chen FileSpec cmd_file (filename, true); 385949d5acde6684b5824a26034457410cdf3823dfeJim Ingham ExecutionContext *exe_ctx = NULL; // Just use the default context. 386246621a2afb9848d96a1beea1d790f433fce6ed4Michael Sartain bool echo_commands = !m_options.m_silent_run; 387949d5acde6684b5824a26034457410cdf3823dfeJim Ingham bool print_results = true; 3886fefc3a3915bcaf899b9179c43b1b7b2f693b3adEnrico Granata bool stop_on_error = m_options.m_stop_on_error.OptionWasSet() ? (bool)m_options.m_stop_on_error : m_interpreter.GetStopCmdSourceOnError(); 389949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 3906fefc3a3915bcaf899b9179c43b1b7b2f693b3adEnrico Granata m_interpreter.HandleCommandsFromFile (cmd_file, 391949d5acde6684b5824a26034457410cdf3823dfeJim Ingham exe_ctx, 392949d5acde6684b5824a26034457410cdf3823dfeJim Ingham m_options.m_stop_on_continue, 3936fefc3a3915bcaf899b9179c43b1b7b2f693b3adEnrico Granata stop_on_error, 394949d5acde6684b5824a26034457410cdf3823dfeJim Ingham echo_commands, 39501bc2d493b48e4904e3241a7768e18fdd9bb6835Enrico Granata print_results, 39601bc2d493b48e4904e3241a7768e18fdd9bb6835Enrico Granata eLazyBoolCalculate, 397949d5acde6684b5824a26034457410cdf3823dfeJim Ingham result); 398767af88aa617288e584afcfed055f7755e408542Jim Ingham } 399767af88aa617288e584afcfed055f7755e408542Jim Ingham else 400767af88aa617288e584afcfed055f7755e408542Jim Ingham { 401767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendErrorWithFormat("'%s' takes exactly one executable filename argument.\n", GetCommandName()); 402767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusFailed); 403767af88aa617288e584afcfed055f7755e408542Jim Ingham } 404767af88aa617288e584afcfed055f7755e408542Jim Ingham return result.Succeeded(); 405767af88aa617288e584afcfed055f7755e408542Jim Ingham 406767af88aa617288e584afcfed055f7755e408542Jim Ingham } 407da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandOptions m_options; 408767af88aa617288e584afcfed055f7755e408542Jim Ingham}; 409767af88aa617288e584afcfed055f7755e408542Jim Ingham 410b344843f75ef893762c93fd0a22d2d45712ce74dGreg ClaytonOptionDefinition 411949d5acde6684b5824a26034457410cdf3823dfeJim InghamCommandObjectCommandsSource::CommandOptions::g_option_table[] = 412949d5acde6684b5824a26034457410cdf3823dfeJim Ingham{ 413949d5acde6684b5824a26034457410cdf3823dfeJim Ingham{ LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', required_argument, NULL, 0, eArgTypeBoolean, "If true, stop executing commands on error."}, 414949d5acde6684b5824a26034457410cdf3823dfeJim Ingham{ LLDB_OPT_SET_ALL, false, "stop-on-continue", 'c', required_argument, NULL, 0, eArgTypeBoolean, "If true, stop executing commands on continue."}, 415246621a2afb9848d96a1beea1d790f433fce6ed4Michael Sartain{ LLDB_OPT_SET_ALL, false, "silent-run", 's', required_argument, NULL, 0, eArgTypeBoolean, "If true don't echo commands while executing."}, 416949d5acde6684b5824a26034457410cdf3823dfeJim Ingham{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 417949d5acde6684b5824a26034457410cdf3823dfeJim Ingham}; 418949d5acde6684b5824a26034457410cdf3823dfeJim Ingham 419767af88aa617288e584afcfed055f7755e408542Jim Ingham#pragma mark CommandObjectCommandsAlias 420767af88aa617288e584afcfed055f7755e408542Jim Ingham//------------------------------------------------------------------------- 421767af88aa617288e584afcfed055f7755e408542Jim Ingham// CommandObjectCommandsAlias 422767af88aa617288e584afcfed055f7755e408542Jim Ingham//------------------------------------------------------------------------- 423767af88aa617288e584afcfed055f7755e408542Jim Ingham 424c2a2825d787be5459fc55264e55b6020ff62f68aEnrico Granatastatic const char *g_python_command_instructions = "Enter your Python command(s). Type 'DONE' to end.\n" 425c2a2825d787be5459fc55264e55b6020ff62f68aEnrico Granata "You must define a Python function with this signature:\n" 426c1ca9dcd0e8a1c7c5a882281afdd2a5145026fd0Enrico Granata "def my_command_impl(debugger, args, result, internal_dict):"; 427c2a2825d787be5459fc55264e55b6020ff62f68aEnrico Granata 428c2a2825d787be5459fc55264e55b6020ff62f68aEnrico Granata 429da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsAlias : public CommandObjectRaw 430767af88aa617288e584afcfed055f7755e408542Jim Ingham{ 431c2a2825d787be5459fc55264e55b6020ff62f68aEnrico Granata 432c2a2825d787be5459fc55264e55b6020ff62f68aEnrico Granata 433767af88aa617288e584afcfed055f7755e408542Jim Inghampublic: 434238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton CommandObjectCommandsAlias (CommandInterpreter &interpreter) : 435da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectRaw (interpreter, 43640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton "command alias", 437abb507ae79e20ab2dd8365049921df73a24c95a5Caroline Tice "Allow users to define their own debugger command abbreviations.", 43843b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice NULL) 439767af88aa617288e584afcfed055f7755e408542Jim Ingham { 440767af88aa617288e584afcfed055f7755e408542Jim Ingham SetHelpLong( 441767af88aa617288e584afcfed055f7755e408542Jim Ingham "'alias' allows the user to create a short-cut or abbreviation for long \n\ 442767af88aa617288e584afcfed055f7755e408542Jim Ingham commands, multi-word commands, and commands that take particular options. \n\ 443767af88aa617288e584afcfed055f7755e408542Jim Ingham Below are some simple examples of how one might use the 'alias' command: \n\ 4444049bc3c000c15a1815d2ff82c3e596e303ded0fJason Molenda \n 'command alias sc script' // Creates the abbreviation 'sc' for the 'script' \n\ 44531fbb64aee1432672f776610e15466cbdc2f9795Caroline Tice // command. \n\ 4464049bc3c000c15a1815d2ff82c3e596e303ded0fJason Molenda 'command alias bp breakpoint' // Creates the abbreviation 'bp' for the 'breakpoint' \n\ 44731fbb64aee1432672f776610e15466cbdc2f9795Caroline Tice // command. Since breakpoint commands are two-word \n\ 44831fbb64aee1432672f776610e15466cbdc2f9795Caroline Tice // commands, the user will still need to enter the \n\ 44931fbb64aee1432672f776610e15466cbdc2f9795Caroline Tice // second word after 'bp', e.g. 'bp enable' or \n\ 45031fbb64aee1432672f776610e15466cbdc2f9795Caroline Tice // 'bp delete'. \n\ 4514049bc3c000c15a1815d2ff82c3e596e303ded0fJason Molenda 'command alias bpl breakpoint list' // Creates the abbreviation 'bpl' for the \n\ 45231fbb64aee1432672f776610e15466cbdc2f9795Caroline Tice // two-word command 'breakpoint list'. \n\ 453767af88aa617288e584afcfed055f7755e408542Jim Ingham \nAn alias can include some options for the command, with the values either \n\ 454767af88aa617288e584afcfed055f7755e408542Jim Ingham filled in at the time the alias is created, or specified as positional \n\ 455767af88aa617288e584afcfed055f7755e408542Jim Ingham arguments, to be filled in when the alias is invoked. The following example \n\ 456767af88aa617288e584afcfed055f7755e408542Jim Ingham shows how to create aliases with options: \n\ 457767af88aa617288e584afcfed055f7755e408542Jim Ingham \n\ 4584049bc3c000c15a1815d2ff82c3e596e303ded0fJason Molenda 'command alias bfl breakpoint set -f %1 -l %2' \n\ 459767af88aa617288e584afcfed055f7755e408542Jim Ingham \nThis creates the abbreviation 'bfl' (for break-file-line), with the -f and -l \n\ 460767af88aa617288e584afcfed055f7755e408542Jim Ingham options already part of the alias. So if the user wants to set a breakpoint \n\ 461767af88aa617288e584afcfed055f7755e408542Jim Ingham by file and line without explicitly having to use the -f and -l options, the \n\ 462767af88aa617288e584afcfed055f7755e408542Jim Ingham user can now use 'bfl' instead. The '%1' and '%2' are positional placeholders \n\ 463767af88aa617288e584afcfed055f7755e408542Jim Ingham for the actual arguments that will be passed when the alias command is used. \n\ 464767af88aa617288e584afcfed055f7755e408542Jim Ingham The number in the placeholder refers to the position/order the actual value \n\ 465536f633e2218f306f94c47398f43f0c7b46137d6Jim Ingham occupies when the alias is used. All the occurrences of '%1' in the alias \n\ 466767af88aa617288e584afcfed055f7755e408542Jim Ingham will be replaced with the first argument, all the occurrences of '%2' in the \n\ 467767af88aa617288e584afcfed055f7755e408542Jim Ingham alias will be replaced with the second argument, and so on. This also allows \n\ 468767af88aa617288e584afcfed055f7755e408542Jim Ingham actual arguments to be used multiple times within an alias (see 'process \n\ 469536f633e2218f306f94c47398f43f0c7b46137d6Jim Ingham launch' example below). \n\ 470536f633e2218f306f94c47398f43f0c7b46137d6Jim Ingham Note: the positional arguments must substitute as whole words in the resultant\n\ 471536f633e2218f306f94c47398f43f0c7b46137d6Jim Ingham command, so you can't at present do something like:\n\ 472536f633e2218f306f94c47398f43f0c7b46137d6Jim Ingham \n\ 4734049bc3c000c15a1815d2ff82c3e596e303ded0fJason Molenda command alias bcppfl breakpoint set -f %1.cpp -l %2\n\ 474536f633e2218f306f94c47398f43f0c7b46137d6Jim Ingham \n\ 475536f633e2218f306f94c47398f43f0c7b46137d6Jim Ingham to get the file extension \".cpp\" automatically appended. For more complex\n\ 476536f633e2218f306f94c47398f43f0c7b46137d6Jim Ingham aliasing, use the \"command regex\" command instead.\n\ 477536f633e2218f306f94c47398f43f0c7b46137d6Jim Ingham \nSo in the 'bfl' case, the actual file value will be \n\ 478767af88aa617288e584afcfed055f7755e408542Jim Ingham filled in with the first argument following 'bfl' and the actual line number \n\ 479767af88aa617288e584afcfed055f7755e408542Jim Ingham value will be filled in with the second argument. The user would use this \n\ 480767af88aa617288e584afcfed055f7755e408542Jim Ingham alias as follows: \n\ 4814049bc3c000c15a1815d2ff82c3e596e303ded0fJason Molenda \n (lldb) command alias bfl breakpoint set -f %1 -l %2 \n\ 482a3aff73b5151c97b3adb1cea3022df967e33db45Sean Callanan <... some time later ...> \n\ 48331fbb64aee1432672f776610e15466cbdc2f9795Caroline Tice (lldb) bfl my-file.c 137 \n\ 484767af88aa617288e584afcfed055f7755e408542Jim Ingham \nThis would be the same as if the user had entered \n\ 485767af88aa617288e584afcfed055f7755e408542Jim Ingham 'breakpoint set -f my-file.c -l 137'. \n\ 486767af88aa617288e584afcfed055f7755e408542Jim Ingham \nAnother example: \n\ 4874049bc3c000c15a1815d2ff82c3e596e303ded0fJason Molenda \n (lldb) command alias pltty process launch -s -o %1 -e %1 \n\ 48831fbb64aee1432672f776610e15466cbdc2f9795Caroline Tice (lldb) pltty /dev/tty0 \n\ 489a3aff73b5151c97b3adb1cea3022df967e33db45Sean Callanan // becomes 'process launch -s -o /dev/tty0 -e /dev/tty0' \n\ 490767af88aa617288e584afcfed055f7755e408542Jim Ingham \nIf the user always wanted to pass the same value to a particular option, the \n\ 491767af88aa617288e584afcfed055f7755e408542Jim Ingham alias could be defined with that value directly in the alias as a constant, \n\ 492767af88aa617288e584afcfed055f7755e408542Jim Ingham rather than using a positional placeholder: \n\ 4934049bc3c000c15a1815d2ff82c3e596e303ded0fJason Molenda \n command alias bl3 breakpoint set -f %1 -l 3 // Always sets a breakpoint on line \n\ 494a3aff73b5151c97b3adb1cea3022df967e33db45Sean Callanan // 3 of whatever file is indicated. \n"); 495767af88aa617288e584afcfed055f7755e408542Jim Ingham 49643b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice CommandArgumentEntry arg1; 49743b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice CommandArgumentEntry arg2; 49843b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice CommandArgumentEntry arg3; 49943b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice CommandArgumentData alias_arg; 50043b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice CommandArgumentData cmd_arg; 50143b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice CommandArgumentData options_arg; 50243b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 50343b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // Define the first (and only) variant of this arg. 50443b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice alias_arg.arg_type = eArgTypeAliasName; 50543b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice alias_arg.arg_repetition = eArgRepeatPlain; 50643b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 50743b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 50843b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice arg1.push_back (alias_arg); 50943b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 51043b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // Define the first (and only) variant of this arg. 51143b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice cmd_arg.arg_type = eArgTypeCommandName; 51243b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice cmd_arg.arg_repetition = eArgRepeatPlain; 51343b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 51443b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 51543b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice arg2.push_back (cmd_arg); 51643b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 51743b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // Define the first (and only) variant of this arg. 51843b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice options_arg.arg_type = eArgTypeAliasOptions; 51943b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice options_arg.arg_repetition = eArgRepeatOptional; 52043b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 52143b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 52243b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice arg3.push_back (options_arg); 52343b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 52443b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // Push the data for the first argument into the m_arguments vector. 52543b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice m_arguments.push_back (arg1); 52643b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice m_arguments.push_back (arg2); 52743b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice m_arguments.push_back (arg3); 528767af88aa617288e584afcfed055f7755e408542Jim Ingham } 529767af88aa617288e584afcfed055f7755e408542Jim Ingham 530767af88aa617288e584afcfed055f7755e408542Jim Ingham ~CommandObjectCommandsAlias () 531767af88aa617288e584afcfed055f7755e408542Jim Ingham { 532767af88aa617288e584afcfed055f7755e408542Jim Ingham } 533767af88aa617288e584afcfed055f7755e408542Jim Ingham 534da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 535da26bd203cbb104291b39891febf7481794f205fJim Ingham virtual bool 536da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (const char *raw_command_line, CommandReturnObject &result) 537e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 538e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice Args args (raw_command_line); 539e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice std::string raw_command_string (raw_command_line); 540e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 541e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice size_t argc = args.GetArgumentCount(); 542e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 543e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice if (argc < 2) 544e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 545e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice result.AppendError ("'alias' requires at least two arguments"); 546e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice result.SetStatus (eReturnStatusFailed); 547e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice return false; 548e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 549e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 550e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // Get the alias command. 551e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 552e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice const std::string alias_command = args.GetArgumentAtIndex (0); 553c2a2825d787be5459fc55264e55b6020ff62f68aEnrico Granata 554e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // Strip the new alias name off 'raw_command_string' (leave it on args, which gets passed to 'Execute', which 555e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // does the stripping itself. 556e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice size_t pos = raw_command_string.find (alias_command); 557e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice if (pos == 0) 558e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 559e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice raw_command_string = raw_command_string.substr (alias_command.size()); 560e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice pos = raw_command_string.find_first_not_of (' '); 561e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice if ((pos != std::string::npos) && (pos > 0)) 562e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice raw_command_string = raw_command_string.substr (pos); 563e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 564e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice else 565e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 566e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice result.AppendError ("Error parsing command string. No alias created."); 567e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice result.SetStatus (eReturnStatusFailed); 568e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice return false; 569e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 570e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 571e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 572e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // Verify that the command is alias-able. 573e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice if (m_interpreter.CommandExists (alias_command.c_str())) 574e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 575e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be redefined.\n", 576e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice alias_command.c_str()); 577e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice result.SetStatus (eReturnStatusFailed); 578e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice return false; 579e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 580e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 581e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // Get CommandObject that is being aliased. The command name is read from the front of raw_command_string. 582e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // raw_command_string is returned with the name of the command object stripped off the front. 583e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice CommandObject *cmd_obj = m_interpreter.GetCommandObjectForCommand (raw_command_string); 584e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 585e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice if (!cmd_obj) 586e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 5879c236733d43e6250c8a5671a438f4a2afeb9c0b2Greg Clayton result.AppendErrorWithFormat ("invalid command given to 'alias'. '%s' does not begin with a valid command." 588e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice " No alias created.", raw_command_string.c_str()); 589e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice result.SetStatus (eReturnStatusFailed); 590e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice return false; 591e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 592e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice else if (!cmd_obj->WantsRawCommandString ()) 593e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 594e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // Note that args was initialized with the original command, and has not been updated to this point. 595e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // Therefore can we pass it to the version of Execute that does not need/expect raw input in the alias. 596da26bd203cbb104291b39891febf7481794f205fJim Ingham return HandleAliasingNormalCommand (args, result); 597e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 598e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice else 599e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 600da26bd203cbb104291b39891febf7481794f205fJim Ingham return HandleAliasingRawCommand (alias_command, raw_command_string, *cmd_obj, result); 601da26bd203cbb104291b39891febf7481794f205fJim Ingham } 602da26bd203cbb104291b39891febf7481794f205fJim Ingham return result.Succeeded(); 603da26bd203cbb104291b39891febf7481794f205fJim Ingham } 604da26bd203cbb104291b39891febf7481794f205fJim Ingham 605da26bd203cbb104291b39891febf7481794f205fJim Ingham bool 606da26bd203cbb104291b39891febf7481794f205fJim Ingham HandleAliasingRawCommand (const std::string &alias_command, std::string &raw_command_string, CommandObject &cmd_obj, CommandReturnObject &result) 607da26bd203cbb104291b39891febf7481794f205fJim Ingham { 608e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // Verify & handle any options/arguments passed to the alias command 609e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 610e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector); 611e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice OptionArgVector *option_arg_vector = option_arg_vector_sp.get(); 612e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 613da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj.GetCommandName(), false); 6145ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice 6155ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice if (!m_interpreter.ProcessAliasOptionsArgs (cmd_obj_sp, raw_command_string.c_str(), option_arg_vector_sp)) 616e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 6175ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice result.AppendError ("Unable to create requested alias.\n"); 6185ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice result.SetStatus (eReturnStatusFailed); 6195ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice return false; 620e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 621e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 622e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice // Create the alias 623e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice if (m_interpreter.AliasExists (alias_command.c_str()) 624e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice || m_interpreter.UserCommandExists (alias_command.c_str())) 625e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 626e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice OptionArgVectorSP temp_option_arg_sp (m_interpreter.GetAliasOptions (alias_command.c_str())); 627e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice if (temp_option_arg_sp.get()) 628e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice { 629e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice if (option_arg_vector->size() == 0) 630e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice m_interpreter.RemoveAliasOptions (alias_command.c_str()); 631e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 632e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n", 633e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice alias_command.c_str()); 634e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 635e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice 63656d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice if (cmd_obj_sp) 63756d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice { 63856d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp); 63956d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice if (option_arg_vector->size() > 0) 64056d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp); 64156d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice result.SetStatus (eReturnStatusSuccessFinishNoResult); 64256d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice } 64356d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice else 64456d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice { 64556d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice result.AppendError ("Unable to create requested alias.\n"); 64656d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice result.SetStatus (eReturnStatusFailed); 64756d2fc45b9461d50054af20c33b836eb8ebd93f5Caroline Tice } 648da26bd203cbb104291b39891febf7481794f205fJim Ingham return result.Succeeded (); 649e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice } 650da26bd203cbb104291b39891febf7481794f205fJim Ingham 651767af88aa617288e584afcfed055f7755e408542Jim Ingham bool 652da26bd203cbb104291b39891febf7481794f205fJim Ingham HandleAliasingNormalCommand (Args& args, CommandReturnObject &result) 653767af88aa617288e584afcfed055f7755e408542Jim Ingham { 6548bb61f099795a3fd98edf655c3e6899cd2668f6cCaroline Tice size_t argc = args.GetArgumentCount(); 655767af88aa617288e584afcfed055f7755e408542Jim Ingham 656767af88aa617288e584afcfed055f7755e408542Jim Ingham if (argc < 2) 65754e7afa84d945f9137f9372ecde432f9e1a702fcGreg Clayton { 658767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendError ("'alias' requires at least two arguments"); 659767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusFailed); 660767af88aa617288e584afcfed055f7755e408542Jim Ingham return false; 66154e7afa84d945f9137f9372ecde432f9e1a702fcGreg Clayton } 662767af88aa617288e584afcfed055f7755e408542Jim Ingham 663767af88aa617288e584afcfed055f7755e408542Jim Ingham const std::string alias_command = args.GetArgumentAtIndex(0); 664767af88aa617288e584afcfed055f7755e408542Jim Ingham const std::string actual_command = args.GetArgumentAtIndex(1); 665767af88aa617288e584afcfed055f7755e408542Jim Ingham 666767af88aa617288e584afcfed055f7755e408542Jim Ingham args.Shift(); // Shift the alias command word off the argument vector. 667767af88aa617288e584afcfed055f7755e408542Jim Ingham args.Shift(); // Shift the old command word off the argument vector. 668767af88aa617288e584afcfed055f7755e408542Jim Ingham 669767af88aa617288e584afcfed055f7755e408542Jim Ingham // Verify that the command is alias'able, and get the appropriate command object. 670767af88aa617288e584afcfed055f7755e408542Jim Ingham 671238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton if (m_interpreter.CommandExists (alias_command.c_str())) 672767af88aa617288e584afcfed055f7755e408542Jim Ingham { 673767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be redefined.\n", 674767af88aa617288e584afcfed055f7755e408542Jim Ingham alias_command.c_str()); 675767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusFailed); 676767af88aa617288e584afcfed055f7755e408542Jim Ingham } 677767af88aa617288e584afcfed055f7755e408542Jim Ingham else 678767af88aa617288e584afcfed055f7755e408542Jim Ingham { 679238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton CommandObjectSP command_obj_sp(m_interpreter.GetCommandSPExact (actual_command.c_str(), true)); 680767af88aa617288e584afcfed055f7755e408542Jim Ingham CommandObjectSP subcommand_obj_sp; 681767af88aa617288e584afcfed055f7755e408542Jim Ingham bool use_subcommand = false; 682767af88aa617288e584afcfed055f7755e408542Jim Ingham if (command_obj_sp.get()) 683767af88aa617288e584afcfed055f7755e408542Jim Ingham { 684767af88aa617288e584afcfed055f7755e408542Jim Ingham CommandObject *cmd_obj = command_obj_sp.get(); 68554e7afa84d945f9137f9372ecde432f9e1a702fcGreg Clayton CommandObject *sub_cmd_obj = NULL; 686767af88aa617288e584afcfed055f7755e408542Jim Ingham OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector); 687767af88aa617288e584afcfed055f7755e408542Jim Ingham OptionArgVector *option_arg_vector = option_arg_vector_sp.get(); 688767af88aa617288e584afcfed055f7755e408542Jim Ingham 689e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice while (cmd_obj->IsMultiwordObject() && args.GetArgumentCount() > 0) 690767af88aa617288e584afcfed055f7755e408542Jim Ingham { 691767af88aa617288e584afcfed055f7755e408542Jim Ingham if (argc >= 3) 692767af88aa617288e584afcfed055f7755e408542Jim Ingham { 693767af88aa617288e584afcfed055f7755e408542Jim Ingham const std::string sub_command = args.GetArgumentAtIndex(0); 694767af88aa617288e584afcfed055f7755e408542Jim Ingham assert (sub_command.length() != 0); 69513193d5ae15f194102c14a5ccdc46e8db5c3d95fGreg Clayton subcommand_obj_sp = cmd_obj->GetSubcommandSP (sub_command.c_str()); 696767af88aa617288e584afcfed055f7755e408542Jim Ingham if (subcommand_obj_sp.get()) 697767af88aa617288e584afcfed055f7755e408542Jim Ingham { 698767af88aa617288e584afcfed055f7755e408542Jim Ingham sub_cmd_obj = subcommand_obj_sp.get(); 699767af88aa617288e584afcfed055f7755e408542Jim Ingham use_subcommand = true; 700767af88aa617288e584afcfed055f7755e408542Jim Ingham args.Shift(); // Shift the sub_command word off the argument vector. 701e0da7a5ba288669df3a4d51059aa0f78f729c6b1Caroline Tice cmd_obj = sub_cmd_obj; 702767af88aa617288e584afcfed055f7755e408542Jim Ingham } 703767af88aa617288e584afcfed055f7755e408542Jim Ingham else 704767af88aa617288e584afcfed055f7755e408542Jim Ingham { 7055d53b621dea6a2ca6ece7528b22d089f864ae18fCaroline Tice result.AppendErrorWithFormat("'%s' is not a valid sub-command of '%s'. " 7065d53b621dea6a2ca6ece7528b22d089f864ae18fCaroline Tice "Unable to create alias.\n", 7075d53b621dea6a2ca6ece7528b22d089f864ae18fCaroline Tice sub_command.c_str(), actual_command.c_str()); 708767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusFailed); 709767af88aa617288e584afcfed055f7755e408542Jim Ingham return false; 710767af88aa617288e584afcfed055f7755e408542Jim Ingham } 711767af88aa617288e584afcfed055f7755e408542Jim Ingham } 712767af88aa617288e584afcfed055f7755e408542Jim Ingham } 713767af88aa617288e584afcfed055f7755e408542Jim Ingham 714767af88aa617288e584afcfed055f7755e408542Jim Ingham // Verify & handle any options/arguments passed to the alias command 715767af88aa617288e584afcfed055f7755e408542Jim Ingham 716767af88aa617288e584afcfed055f7755e408542Jim Ingham if (args.GetArgumentCount () > 0) 717767af88aa617288e584afcfed055f7755e408542Jim Ingham { 7185ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice CommandObjectSP tmp_sp = m_interpreter.GetCommandSPExact (cmd_obj->GetCommandName(), false); 7195ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice if (use_subcommand) 7205ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice tmp_sp = m_interpreter.GetCommandSPExact (sub_cmd_obj->GetCommandName(), false); 7215ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice 7225ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice std::string args_string; 7235ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice args.GetCommandString (args_string); 7245ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice 7255ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice if (!m_interpreter.ProcessAliasOptionsArgs (tmp_sp, args_string.c_str(), option_arg_vector_sp)) 7265ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice { 7275ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice result.AppendError ("Unable to create requested alias.\n"); 7285ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice result.SetStatus (eReturnStatusFailed); 7295ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice return false; 7305ddbe214153f60f8ab62ba98dea089a21f1779f3Caroline Tice } 731767af88aa617288e584afcfed055f7755e408542Jim Ingham } 732767af88aa617288e584afcfed055f7755e408542Jim Ingham 733767af88aa617288e584afcfed055f7755e408542Jim Ingham // Create the alias. 734767af88aa617288e584afcfed055f7755e408542Jim Ingham 735238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton if (m_interpreter.AliasExists (alias_command.c_str()) 736238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton || m_interpreter.UserCommandExists (alias_command.c_str())) 737767af88aa617288e584afcfed055f7755e408542Jim Ingham { 738238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton OptionArgVectorSP tmp_option_arg_sp (m_interpreter.GetAliasOptions (alias_command.c_str())); 739767af88aa617288e584afcfed055f7755e408542Jim Ingham if (tmp_option_arg_sp.get()) 740767af88aa617288e584afcfed055f7755e408542Jim Ingham { 741767af88aa617288e584afcfed055f7755e408542Jim Ingham if (option_arg_vector->size() == 0) 742238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton m_interpreter.RemoveAliasOptions (alias_command.c_str()); 743767af88aa617288e584afcfed055f7755e408542Jim Ingham } 744767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n", 745767af88aa617288e584afcfed055f7755e408542Jim Ingham alias_command.c_str()); 746767af88aa617288e584afcfed055f7755e408542Jim Ingham } 747767af88aa617288e584afcfed055f7755e408542Jim Ingham 748767af88aa617288e584afcfed055f7755e408542Jim Ingham if (use_subcommand) 749238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton m_interpreter.AddAlias (alias_command.c_str(), subcommand_obj_sp); 750767af88aa617288e584afcfed055f7755e408542Jim Ingham else 751238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton m_interpreter.AddAlias (alias_command.c_str(), command_obj_sp); 752767af88aa617288e584afcfed055f7755e408542Jim Ingham if (option_arg_vector->size() > 0) 753238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp); 754767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 755767af88aa617288e584afcfed055f7755e408542Jim Ingham } 756767af88aa617288e584afcfed055f7755e408542Jim Ingham else 757767af88aa617288e584afcfed055f7755e408542Jim Ingham { 758767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendErrorWithFormat ("'%s' is not an existing command.\n", actual_command.c_str()); 759767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusFailed); 760e6866a3819d68be21004ffdf773e36e7f00a6a26Caroline Tice return false; 761767af88aa617288e584afcfed055f7755e408542Jim Ingham } 762767af88aa617288e584afcfed055f7755e408542Jim Ingham } 763767af88aa617288e584afcfed055f7755e408542Jim Ingham 764767af88aa617288e584afcfed055f7755e408542Jim Ingham return result.Succeeded(); 765767af88aa617288e584afcfed055f7755e408542Jim Ingham } 766da26bd203cbb104291b39891febf7481794f205fJim Ingham 767767af88aa617288e584afcfed055f7755e408542Jim Ingham}; 768767af88aa617288e584afcfed055f7755e408542Jim Ingham 769767af88aa617288e584afcfed055f7755e408542Jim Ingham#pragma mark CommandObjectCommandsUnalias 770767af88aa617288e584afcfed055f7755e408542Jim Ingham//------------------------------------------------------------------------- 771767af88aa617288e584afcfed055f7755e408542Jim Ingham// CommandObjectCommandsUnalias 772767af88aa617288e584afcfed055f7755e408542Jim Ingham//------------------------------------------------------------------------- 773767af88aa617288e584afcfed055f7755e408542Jim Ingham 774da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsUnalias : public CommandObjectParsed 775767af88aa617288e584afcfed055f7755e408542Jim Ingham{ 776767af88aa617288e584afcfed055f7755e408542Jim Inghampublic: 777238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton CommandObjectCommandsUnalias (CommandInterpreter &interpreter) : 778da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectParsed (interpreter, 77940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton "command unalias", 780146292c83470680b98a4e4046428e0849e1ffe8fCaroline Tice "Allow the user to remove/delete a user-defined command abbreviation.", 78143b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice NULL) 782767af88aa617288e584afcfed055f7755e408542Jim Ingham { 78343b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice CommandArgumentEntry arg; 78443b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice CommandArgumentData alias_arg; 78543b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 78643b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // Define the first (and only) variant of this arg. 78743b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice alias_arg.arg_type = eArgTypeAliasName; 78843b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice alias_arg.arg_repetition = eArgRepeatPlain; 78943b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 79043b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // There is only one variant this argument could be; put it into the argument entry. 79143b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice arg.push_back (alias_arg); 79243b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice 79343b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice // Push the data for the first argument into the m_arguments vector. 79443b014aa33e20e61790e16ed69a2c57aae2fbc6eCaroline Tice m_arguments.push_back (arg); 795767af88aa617288e584afcfed055f7755e408542Jim Ingham } 796767af88aa617288e584afcfed055f7755e408542Jim Ingham 797767af88aa617288e584afcfed055f7755e408542Jim Ingham ~CommandObjectCommandsUnalias() 798767af88aa617288e584afcfed055f7755e408542Jim Ingham { 799767af88aa617288e584afcfed055f7755e408542Jim Ingham } 800767af88aa617288e584afcfed055f7755e408542Jim Ingham 801da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 802767af88aa617288e584afcfed055f7755e408542Jim Ingham bool 803da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (Args& args, CommandReturnObject &result) 804767af88aa617288e584afcfed055f7755e408542Jim Ingham { 805767af88aa617288e584afcfed055f7755e408542Jim Ingham CommandObject::CommandMap::iterator pos; 806767af88aa617288e584afcfed055f7755e408542Jim Ingham CommandObject *cmd_obj; 807767af88aa617288e584afcfed055f7755e408542Jim Ingham 808767af88aa617288e584afcfed055f7755e408542Jim Ingham if (args.GetArgumentCount() != 0) 809767af88aa617288e584afcfed055f7755e408542Jim Ingham { 810767af88aa617288e584afcfed055f7755e408542Jim Ingham const char *command_name = args.GetArgumentAtIndex(0); 811238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton cmd_obj = m_interpreter.GetCommandObject(command_name); 812767af88aa617288e584afcfed055f7755e408542Jim Ingham if (cmd_obj) 813767af88aa617288e584afcfed055f7755e408542Jim Ingham { 814238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton if (m_interpreter.CommandExists (command_name)) 815767af88aa617288e584afcfed055f7755e408542Jim Ingham { 816767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be removed.\n", 817767af88aa617288e584afcfed055f7755e408542Jim Ingham command_name); 818767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusFailed); 819767af88aa617288e584afcfed055f7755e408542Jim Ingham } 820767af88aa617288e584afcfed055f7755e408542Jim Ingham else 821767af88aa617288e584afcfed055f7755e408542Jim Ingham { 822767af88aa617288e584afcfed055f7755e408542Jim Ingham 823238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton if (m_interpreter.RemoveAlias (command_name) == false) 824767af88aa617288e584afcfed055f7755e408542Jim Ingham { 825238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton if (m_interpreter.AliasExists (command_name)) 826767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendErrorWithFormat ("Error occurred while attempting to unalias '%s'.\n", 827767af88aa617288e584afcfed055f7755e408542Jim Ingham command_name); 828767af88aa617288e584afcfed055f7755e408542Jim Ingham else 829767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendErrorWithFormat ("'%s' is not an existing alias.\n", command_name); 830767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusFailed); 831767af88aa617288e584afcfed055f7755e408542Jim Ingham } 832767af88aa617288e584afcfed055f7755e408542Jim Ingham else 833767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusSuccessFinishNoResult); 834767af88aa617288e584afcfed055f7755e408542Jim Ingham } 835767af88aa617288e584afcfed055f7755e408542Jim Ingham } 836767af88aa617288e584afcfed055f7755e408542Jim Ingham else 837767af88aa617288e584afcfed055f7755e408542Jim Ingham { 838767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendErrorWithFormat ("'%s' is not a known command.\nTry 'help' to see a " 839767af88aa617288e584afcfed055f7755e408542Jim Ingham "current list of commands.\n", 840767af88aa617288e584afcfed055f7755e408542Jim Ingham command_name); 841767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusFailed); 842767af88aa617288e584afcfed055f7755e408542Jim Ingham } 843767af88aa617288e584afcfed055f7755e408542Jim Ingham } 844767af88aa617288e584afcfed055f7755e408542Jim Ingham else 845767af88aa617288e584afcfed055f7755e408542Jim Ingham { 846767af88aa617288e584afcfed055f7755e408542Jim Ingham result.AppendError ("must call 'unalias' with a valid alias"); 847767af88aa617288e584afcfed055f7755e408542Jim Ingham result.SetStatus (eReturnStatusFailed); 848767af88aa617288e584afcfed055f7755e408542Jim Ingham } 849767af88aa617288e584afcfed055f7755e408542Jim Ingham 850767af88aa617288e584afcfed055f7755e408542Jim Ingham return result.Succeeded(); 851767af88aa617288e584afcfed055f7755e408542Jim Ingham } 852767af88aa617288e584afcfed055f7755e408542Jim Ingham}; 853767af88aa617288e584afcfed055f7755e408542Jim Ingham 854d12aeab33bab559e138307f599077da3918a3238Greg Clayton//------------------------------------------------------------------------- 855d12aeab33bab559e138307f599077da3918a3238Greg Clayton// CommandObjectCommandsAddRegex 856d12aeab33bab559e138307f599077da3918a3238Greg Clayton//------------------------------------------------------------------------- 857da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark CommandObjectCommandsAddRegex 858d12aeab33bab559e138307f599077da3918a3238Greg Clayton 859da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsAddRegex : public CommandObjectParsed 860d12aeab33bab559e138307f599077da3918a3238Greg Clayton{ 861d12aeab33bab559e138307f599077da3918a3238Greg Claytonpublic: 862d12aeab33bab559e138307f599077da3918a3238Greg Clayton CommandObjectCommandsAddRegex (CommandInterpreter &interpreter) : 863da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectParsed (interpreter, 86440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton "command regex", 865d12aeab33bab559e138307f599077da3918a3238Greg Clayton "Allow the user to create a regular expression command.", 86640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton "command regex <cmd-name> [s/<regex>/<subst>/ ...]"), 867d12aeab33bab559e138307f599077da3918a3238Greg Clayton m_options (interpreter) 868d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 86940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton SetHelpLong( 87040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"This command allows the user to create powerful regular expression commands\n" 87140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"with substitutions. The regular expressions and substitutions are specified\n" 87240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"using the regular exression substitution format of:\n" 87340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"\n" 87440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton" s/<regex>/<subst>/\n" 87540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"\n" 87640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"<regex> is a regular expression that can use parenthesis to capture regular\n" 87740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"expression input and substitute the captured matches in the output using %1\n" 87840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"for the first match, %2 for the second, and so on.\n" 87940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"\n" 88040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"The regular expressions can all be specified on the command line if more than\n" 88140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"one argument is provided. If just the command name is provided on the command\n" 88240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"line, then the regular expressions and substitutions can be entered on separate\n" 88340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton" lines, followed by an empty line to terminate the command definition.\n" 88440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"\n" 88540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"EXAMPLES\n" 88640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"\n" 8877acd60a47e145f92e7e19215542aaaa37e5d74a8Sean Callanan"The following example will define a regular expression command named 'f' that\n" 88840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"will call 'finish' if there are no arguments, or 'frame select <frame-idx>' if\n" 88940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton"a number follows 'f':\n" 8907acd60a47e145f92e7e19215542aaaa37e5d74a8Sean Callanan"\n" 8917acd60a47e145f92e7e19215542aaaa37e5d74a8Sean Callanan" (lldb) command regex f s/^$/finish/ 's/([0-9]+)/frame select %1/'\n" 8927acd60a47e145f92e7e19215542aaaa37e5d74a8Sean Callanan"\n" 89340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton ); 894d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 895d12aeab33bab559e138307f599077da3918a3238Greg Clayton 896d12aeab33bab559e138307f599077da3918a3238Greg Clayton ~CommandObjectCommandsAddRegex() 897d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 898d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 899d12aeab33bab559e138307f599077da3918a3238Greg Clayton 900d12aeab33bab559e138307f599077da3918a3238Greg Clayton 901da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 902d12aeab33bab559e138307f599077da3918a3238Greg Clayton bool 903da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (Args& command, CommandReturnObject &result) 904d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 905da26bd203cbb104291b39891febf7481794f205fJim Ingham const size_t argc = command.GetArgumentCount(); 90640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (argc == 0) 907d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 9084049bc3c000c15a1815d2ff82c3e596e303ded0fJason Molenda result.AppendError ("usage: 'command regex <command-name> [s/<regex1>/<subst1>/ s/<regex2>/<subst2>/ ...]'\n"); 90940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton result.SetStatus (eReturnStatusFailed); 91040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 91140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton else 91240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 91340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton Error error; 914da26bd203cbb104291b39891febf7481794f205fJim Ingham const char *name = command.GetArgumentAtIndex(0); 915d12aeab33bab559e138307f599077da3918a3238Greg Clayton m_regex_cmd_ap.reset (new CommandObjectRegexCommand (m_interpreter, 916d12aeab33bab559e138307f599077da3918a3238Greg Clayton name, 917d12aeab33bab559e138307f599077da3918a3238Greg Clayton m_options.GetHelp (), 918d12aeab33bab559e138307f599077da3918a3238Greg Clayton m_options.GetSyntax (), 919d12aeab33bab559e138307f599077da3918a3238Greg Clayton 10)); 92040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 92140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (argc == 1) 922d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 92340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger())); 92440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (reader_sp) 92540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 92640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error =reader_sp->Initialize (CommandObjectCommandsAddRegex::InputReaderCallback, 927d12aeab33bab559e138307f599077da3918a3238Greg Clayton this, // baton 928d12aeab33bab559e138307f599077da3918a3238Greg Clayton eInputReaderGranularityLine, // token size, to pass to callback function 92940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton NULL, // end token 930d12aeab33bab559e138307f599077da3918a3238Greg Clayton "> ", // prompt 93140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton true); // echo input 93240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (error.Success()) 93340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 93440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton m_interpreter.GetDebugger().PushInputReader (reader_sp); 93540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton result.SetStatus (eReturnStatusSuccessFinishNoResult); 93640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return true; 93740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 93840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 93940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 94040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton else 94140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 94240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton for (size_t arg_idx = 1; arg_idx < argc; ++arg_idx) 943d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 944da26bd203cbb104291b39891febf7481794f205fJim Ingham llvm::StringRef arg_strref (command.GetArgumentAtIndex(arg_idx)); 94540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error = AppendRegexSubstitution (arg_strref); 94640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (error.Fail()) 94740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton break; 948d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 94940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 95040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (error.Success()) 951d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 95240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton AddRegexCommandToInterpreter(); 953d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 954d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 95540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (error.Fail()) 95640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 95740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton result.AppendError (error.AsCString()); 95840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton result.SetStatus (eReturnStatusFailed); 95940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 960d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 96140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 962d12aeab33bab559e138307f599077da3918a3238Greg Clayton return result.Succeeded(); 963d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 964d12aeab33bab559e138307f599077da3918a3238Greg Clayton 96540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton Error 96640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton AppendRegexSubstitution (const llvm::StringRef ®ex_sed) 967d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 96840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton Error error; 96940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 97040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (m_regex_cmd_ap.get() == NULL) 97140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 97240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error.SetErrorStringWithFormat("invalid regular expression command object for: '%.*s'", 97340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton (int)regex_sed.size(), 97440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton regex_sed.data()); 97540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return error; 97640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 97740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 97840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton size_t regex_sed_size = regex_sed.size(); 97940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 98040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (regex_sed_size <= 1) 981d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 98240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error.SetErrorStringWithFormat("regular expression substitution string is too short: '%.*s'", 98340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton (int)regex_sed.size(), 98440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton regex_sed.data()); 98540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return error; 986d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 98740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 98840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (regex_sed[0] != 's') 98940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 99040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error.SetErrorStringWithFormat("regular expression substitution string doesn't start with 's': '%.*s'", 99140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton (int)regex_sed.size(), 99240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton regex_sed.data()); 99340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return error; 99440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 99540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton const size_t first_separator_char_pos = 1; 99640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton // use the char that follows 's' as the regex separator character 99740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton // so we can have "s/<regex>/<subst>/" or "s|<regex>|<subst>|" 99840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton const char separator_char = regex_sed[first_separator_char_pos]; 99940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton const size_t second_separator_char_pos = regex_sed.find (separator_char, first_separator_char_pos + 1); 100040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 100140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (second_separator_char_pos == std::string::npos) 100240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 100340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error.SetErrorStringWithFormat("missing second '%c' separator char after '%.*s'", 100440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton separator_char, 100540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton (int)(regex_sed.size() - first_separator_char_pos - 1), 100640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton regex_sed.data() + (first_separator_char_pos + 1)); 100740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return error; 100840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 100940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 101040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton const size_t third_separator_char_pos = regex_sed.find (separator_char, second_separator_char_pos + 1); 101140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 101240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (third_separator_char_pos == std::string::npos) 101340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 101440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error.SetErrorStringWithFormat("missing third '%c' separator char after '%.*s'", 101540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton separator_char, 101640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton (int)(regex_sed.size() - second_separator_char_pos - 1), 101740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton regex_sed.data() + (second_separator_char_pos + 1)); 101840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return error; 101940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 102040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 102140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (third_separator_char_pos != regex_sed_size - 1) 102240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 102340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton // Make sure that everything that follows the last regex 102440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton // separator char 102540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton if (regex_sed.find_first_not_of("\t\n\v\f\r ", third_separator_char_pos + 1) != std::string::npos) 102640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 102740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error.SetErrorStringWithFormat("extra data found after the '%.*s' regular expression substitution string: '%.*s'", 102840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton (int)third_separator_char_pos + 1, 102940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton regex_sed.data(), 103040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton (int)(regex_sed.size() - third_separator_char_pos - 1), 103140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton regex_sed.data() + (third_separator_char_pos + 1)); 103240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return error; 103340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 103440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 103540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 103640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton else if (first_separator_char_pos + 1 == second_separator_char_pos) 103740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 103840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error.SetErrorStringWithFormat("<regex> can't be empty in 's%c<regex>%c<subst>%c' string: '%.*s'", 103940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton separator_char, 104040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton separator_char, 104140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton separator_char, 104240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton (int)regex_sed.size(), 104340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton regex_sed.data()); 104440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return error; 104540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 104640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton else if (second_separator_char_pos + 1 == third_separator_char_pos) 104740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 104840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton error.SetErrorStringWithFormat("<subst> can't be empty in 's%c<regex>%c<subst>%c' string: '%.*s'", 104940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton separator_char, 105040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton separator_char, 105140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton separator_char, 105240e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton (int)regex_sed.size(), 105340e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton regex_sed.data()); 105440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return error; 105540e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 105640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton std::string regex(regex_sed.substr(first_separator_char_pos + 1, second_separator_char_pos - first_separator_char_pos - 1)); 105740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton std::string subst(regex_sed.substr(second_separator_char_pos + 1, third_separator_char_pos - second_separator_char_pos - 1)); 105840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton m_regex_cmd_ap->AddRegexCommand (regex.c_str(), 105940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton subst.c_str()); 106040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton return error; 1061d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1062d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1063d12aeab33bab559e138307f599077da3918a3238Greg Clayton void 106440e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton AddRegexCommandToInterpreter() 1065d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1066d12aeab33bab559e138307f599077da3918a3238Greg Clayton if (m_regex_cmd_ap.get()) 1067d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1068d12aeab33bab559e138307f599077da3918a3238Greg Clayton if (m_regex_cmd_ap->HasRegexEntries()) 1069d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1070d12aeab33bab559e138307f599077da3918a3238Greg Clayton CommandObjectSP cmd_sp (m_regex_cmd_ap.release()); 1071d12aeab33bab559e138307f599077da3918a3238Greg Clayton m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true); 1072d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1073d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1074d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1075d12aeab33bab559e138307f599077da3918a3238Greg Clayton 107640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton void 107740e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton InputReaderDidCancel() 107840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton { 107940e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton m_regex_cmd_ap.reset(); 108040e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton } 108140e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton 1082d12aeab33bab559e138307f599077da3918a3238Greg Clayton static size_t 1083d12aeab33bab559e138307f599077da3918a3238Greg Clayton InputReaderCallback (void *baton, 1084d12aeab33bab559e138307f599077da3918a3238Greg Clayton InputReader &reader, 1085d12aeab33bab559e138307f599077da3918a3238Greg Clayton lldb::InputReaderAction notification, 1086d12aeab33bab559e138307f599077da3918a3238Greg Clayton const char *bytes, 1087da26bd203cbb104291b39891febf7481794f205fJim Ingham size_t bytes_len) 1088da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1089da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectCommandsAddRegex *add_regex_cmd = (CommandObjectCommandsAddRegex *) baton; 1090da26bd203cbb104291b39891febf7481794f205fJim Ingham bool batch_mode = reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode(); 1091da26bd203cbb104291b39891febf7481794f205fJim Ingham 1092da26bd203cbb104291b39891febf7481794f205fJim Ingham switch (notification) 1093da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1094da26bd203cbb104291b39891febf7481794f205fJim Ingham case eInputReaderActivate: 1095da26bd203cbb104291b39891febf7481794f205fJim Ingham if (!batch_mode) 1096da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1097da26bd203cbb104291b39891febf7481794f205fJim Ingham StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream (); 1098da26bd203cbb104291b39891febf7481794f205fJim Ingham out_stream->Printf("%s\n", "Enter regular expressions in the form 's/<regex>/<subst>/' and terminate with an empty line:"); 1099da26bd203cbb104291b39891febf7481794f205fJim Ingham out_stream->Flush(); 1100da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1101da26bd203cbb104291b39891febf7481794f205fJim Ingham break; 1102da26bd203cbb104291b39891febf7481794f205fJim Ingham case eInputReaderReactivate: 1103da26bd203cbb104291b39891febf7481794f205fJim Ingham break; 1104da26bd203cbb104291b39891febf7481794f205fJim Ingham 1105da26bd203cbb104291b39891febf7481794f205fJim Ingham case eInputReaderDeactivate: 1106da26bd203cbb104291b39891febf7481794f205fJim Ingham break; 1107da26bd203cbb104291b39891febf7481794f205fJim Ingham 1108da26bd203cbb104291b39891febf7481794f205fJim Ingham case eInputReaderAsynchronousOutputWritten: 1109da26bd203cbb104291b39891febf7481794f205fJim Ingham break; 1110da26bd203cbb104291b39891febf7481794f205fJim Ingham 1111da26bd203cbb104291b39891febf7481794f205fJim Ingham case eInputReaderGotToken: 1112da26bd203cbb104291b39891febf7481794f205fJim Ingham while (bytes_len > 0 && (bytes[bytes_len-1] == '\r' || bytes[bytes_len-1] == '\n')) 1113da26bd203cbb104291b39891febf7481794f205fJim Ingham --bytes_len; 1114da26bd203cbb104291b39891febf7481794f205fJim Ingham if (bytes_len == 0) 1115da26bd203cbb104291b39891febf7481794f205fJim Ingham reader.SetIsDone(true); 1116da26bd203cbb104291b39891febf7481794f205fJim Ingham else if (bytes) 1117da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1118da26bd203cbb104291b39891febf7481794f205fJim Ingham llvm::StringRef bytes_strref (bytes, bytes_len); 1119da26bd203cbb104291b39891febf7481794f205fJim Ingham Error error (add_regex_cmd->AppendRegexSubstitution (bytes_strref)); 1120da26bd203cbb104291b39891febf7481794f205fJim Ingham if (error.Fail()) 1121da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1122da26bd203cbb104291b39891febf7481794f205fJim Ingham if (!batch_mode) 1123da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1124da26bd203cbb104291b39891febf7481794f205fJim Ingham StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); 1125da26bd203cbb104291b39891febf7481794f205fJim Ingham out_stream->Printf("error: %s\n", error.AsCString()); 1126da26bd203cbb104291b39891febf7481794f205fJim Ingham out_stream->Flush(); 1127da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1128da26bd203cbb104291b39891febf7481794f205fJim Ingham add_regex_cmd->InputReaderDidCancel (); 1129da26bd203cbb104291b39891febf7481794f205fJim Ingham reader.SetIsDone (true); 1130da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1131da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1132da26bd203cbb104291b39891febf7481794f205fJim Ingham break; 1133da26bd203cbb104291b39891febf7481794f205fJim Ingham 1134da26bd203cbb104291b39891febf7481794f205fJim Ingham case eInputReaderInterrupt: 1135da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1136da26bd203cbb104291b39891febf7481794f205fJim Ingham reader.SetIsDone (true); 1137da26bd203cbb104291b39891febf7481794f205fJim Ingham if (!batch_mode) 1138da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1139da26bd203cbb104291b39891febf7481794f205fJim Ingham StreamSP out_stream = reader.GetDebugger().GetAsyncOutputStream(); 1140da26bd203cbb104291b39891febf7481794f205fJim Ingham out_stream->PutCString("Regular expression command creations was cancelled.\n"); 1141da26bd203cbb104291b39891febf7481794f205fJim Ingham out_stream->Flush(); 1142da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1143da26bd203cbb104291b39891febf7481794f205fJim Ingham add_regex_cmd->InputReaderDidCancel (); 1144da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1145da26bd203cbb104291b39891febf7481794f205fJim Ingham break; 1146da26bd203cbb104291b39891febf7481794f205fJim Ingham 1147da26bd203cbb104291b39891febf7481794f205fJim Ingham case eInputReaderEndOfFile: 1148da26bd203cbb104291b39891febf7481794f205fJim Ingham reader.SetIsDone (true); 1149da26bd203cbb104291b39891febf7481794f205fJim Ingham break; 1150da26bd203cbb104291b39891febf7481794f205fJim Ingham 1151da26bd203cbb104291b39891febf7481794f205fJim Ingham case eInputReaderDone: 1152da26bd203cbb104291b39891febf7481794f205fJim Ingham add_regex_cmd->AddRegexCommandToInterpreter(); 1153da26bd203cbb104291b39891febf7481794f205fJim Ingham break; 1154da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1155da26bd203cbb104291b39891febf7481794f205fJim Ingham 1156da26bd203cbb104291b39891febf7481794f205fJim Ingham return bytes_len; 1157da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1158da26bd203cbb104291b39891febf7481794f205fJim Ingham 1159d12aeab33bab559e138307f599077da3918a3238Greg Claytonprivate: 1160102b2c2681c9a830afe25bfea35557421905e42cGreg Clayton std::unique_ptr<CommandObjectRegexCommand> m_regex_cmd_ap; 1161d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1162d12aeab33bab559e138307f599077da3918a3238Greg Clayton class CommandOptions : public Options 1163d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1164d12aeab33bab559e138307f599077da3918a3238Greg Clayton public: 1165d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1166d12aeab33bab559e138307f599077da3918a3238Greg Clayton CommandOptions (CommandInterpreter &interpreter) : 1167d12aeab33bab559e138307f599077da3918a3238Greg Clayton Options (interpreter) 1168d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1169d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1170d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1171d12aeab33bab559e138307f599077da3918a3238Greg Clayton virtual 1172d12aeab33bab559e138307f599077da3918a3238Greg Clayton ~CommandOptions (){} 1173d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1174d12aeab33bab559e138307f599077da3918a3238Greg Clayton virtual Error 1175d12aeab33bab559e138307f599077da3918a3238Greg Clayton SetOptionValue (uint32_t option_idx, const char *option_arg) 1176d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1177d12aeab33bab559e138307f599077da3918a3238Greg Clayton Error error; 11786475c42148a8ea1ca86e5db465db7eca742d897dGreg Clayton const int short_option = m_getopt_table[option_idx].val; 1179d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1180d12aeab33bab559e138307f599077da3918a3238Greg Clayton switch (short_option) 1181d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1182d12aeab33bab559e138307f599077da3918a3238Greg Clayton case 'h': 1183d12aeab33bab559e138307f599077da3918a3238Greg Clayton m_help.assign (option_arg); 1184d12aeab33bab559e138307f599077da3918a3238Greg Clayton break; 1185d12aeab33bab559e138307f599077da3918a3238Greg Clayton case 's': 1186d12aeab33bab559e138307f599077da3918a3238Greg Clayton m_syntax.assign (option_arg); 1187d12aeab33bab559e138307f599077da3918a3238Greg Clayton break; 1188d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1189d12aeab33bab559e138307f599077da3918a3238Greg Clayton default: 11909c236733d43e6250c8a5671a438f4a2afeb9c0b2Greg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 1191d12aeab33bab559e138307f599077da3918a3238Greg Clayton break; 1192d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1193d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1194d12aeab33bab559e138307f599077da3918a3238Greg Clayton return error; 1195d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1196d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1197d12aeab33bab559e138307f599077da3918a3238Greg Clayton void 1198d12aeab33bab559e138307f599077da3918a3238Greg Clayton OptionParsingStarting () 1199d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1200d12aeab33bab559e138307f599077da3918a3238Greg Clayton m_help.clear(); 1201d12aeab33bab559e138307f599077da3918a3238Greg Clayton m_syntax.clear(); 1202d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1203d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1204d12aeab33bab559e138307f599077da3918a3238Greg Clayton const OptionDefinition* 1205d12aeab33bab559e138307f599077da3918a3238Greg Clayton GetDefinitions () 1206d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1207d12aeab33bab559e138307f599077da3918a3238Greg Clayton return g_option_table; 1208d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1209d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1210d12aeab33bab559e138307f599077da3918a3238Greg Clayton // Options table: Required for subclasses of Options. 1211d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1212d12aeab33bab559e138307f599077da3918a3238Greg Clayton static OptionDefinition g_option_table[]; 1213d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1214d12aeab33bab559e138307f599077da3918a3238Greg Clayton const char * 1215d12aeab33bab559e138307f599077da3918a3238Greg Clayton GetHelp () 1216d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1217d12aeab33bab559e138307f599077da3918a3238Greg Clayton if (m_help.empty()) 1218d12aeab33bab559e138307f599077da3918a3238Greg Clayton return NULL; 1219d12aeab33bab559e138307f599077da3918a3238Greg Clayton return m_help.c_str(); 1220d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1221d12aeab33bab559e138307f599077da3918a3238Greg Clayton const char * 1222d12aeab33bab559e138307f599077da3918a3238Greg Clayton GetSyntax () 1223d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1224d12aeab33bab559e138307f599077da3918a3238Greg Clayton if (m_syntax.empty()) 1225d12aeab33bab559e138307f599077da3918a3238Greg Clayton return NULL; 1226d12aeab33bab559e138307f599077da3918a3238Greg Clayton return m_syntax.c_str(); 1227d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1228d12aeab33bab559e138307f599077da3918a3238Greg Clayton // Instance variables to hold the values for command options. 1229d12aeab33bab559e138307f599077da3918a3238Greg Clayton protected: 1230d12aeab33bab559e138307f599077da3918a3238Greg Clayton std::string m_help; 1231d12aeab33bab559e138307f599077da3918a3238Greg Clayton std::string m_syntax; 1232d12aeab33bab559e138307f599077da3918a3238Greg Clayton }; 1233da26bd203cbb104291b39891febf7481794f205fJim Ingham 1234d12aeab33bab559e138307f599077da3918a3238Greg Clayton virtual Options * 1235d12aeab33bab559e138307f599077da3918a3238Greg Clayton GetOptions () 1236d12aeab33bab559e138307f599077da3918a3238Greg Clayton { 1237d12aeab33bab559e138307f599077da3918a3238Greg Clayton return &m_options; 1238d12aeab33bab559e138307f599077da3918a3238Greg Clayton } 1239da26bd203cbb104291b39891febf7481794f205fJim Ingham 1240da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandOptions m_options; 1241d12aeab33bab559e138307f599077da3918a3238Greg Clayton}; 1242d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1243d12aeab33bab559e138307f599077da3918a3238Greg ClaytonOptionDefinition 1244d12aeab33bab559e138307f599077da3918a3238Greg ClaytonCommandObjectCommandsAddRegex::CommandOptions::g_option_table[] = 1245d12aeab33bab559e138307f599077da3918a3238Greg Clayton{ 124640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton{ LLDB_OPT_SET_1, false, "help" , 'h', required_argument, NULL, 0, eArgTypeNone, "The help text to display for this command."}, 1247d12aeab33bab559e138307f599077da3918a3238Greg Clayton{ LLDB_OPT_SET_1, false, "syntax", 's', required_argument, NULL, 0, eArgTypeNone, "A syntax string showing the typical usage syntax."}, 124840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton{ 0 , false, NULL , 0 , 0 , NULL, 0, eArgTypeNone, NULL } 1249d12aeab33bab559e138307f599077da3918a3238Greg Clayton}; 1250d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1251d12aeab33bab559e138307f599077da3918a3238Greg Clayton 1252da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectPythonFunction : public CommandObjectRaw 12536b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata{ 12546b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granataprivate: 12556b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata std::string m_function_name; 12566010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata ScriptedCommandSynchronicity m_synchro; 12575b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata bool m_fetched_help_long; 12586b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 12596b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granatapublic: 12606b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 12616b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandObjectPythonFunction (CommandInterpreter &interpreter, 12626b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata std::string name, 12636010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata std::string funct, 12646010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata ScriptedCommandSynchronicity synch) : 1265da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectRaw (interpreter, 1266da26bd203cbb104291b39891febf7481794f205fJim Ingham name.c_str(), 1267da26bd203cbb104291b39891febf7481794f205fJim Ingham (std::string("Run Python function ") + funct).c_str(), 1268da26bd203cbb104291b39891febf7481794f205fJim Ingham NULL), 1269da26bd203cbb104291b39891febf7481794f205fJim Ingham m_function_name(funct), 12705b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata m_synchro(synch), 12715b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata m_fetched_help_long(false) 12726b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 12736b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 12746b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 12756b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual 12766b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata ~CommandObjectPythonFunction () 12776b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 12786b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 12796b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 12806b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual bool 1281f737d372a9672c9feaedf4b2cd7b16e31357d38eGreg Clayton IsRemovable () const 1282da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1283da26bd203cbb104291b39891febf7481794f205fJim Ingham return true; 1284da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1285da26bd203cbb104291b39891febf7481794f205fJim Ingham 1286da26bd203cbb104291b39891febf7481794f205fJim Ingham const std::string& 1287da26bd203cbb104291b39891febf7481794f205fJim Ingham GetFunctionName () 1288da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1289da26bd203cbb104291b39891febf7481794f205fJim Ingham return m_function_name; 1290da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1291da26bd203cbb104291b39891febf7481794f205fJim Ingham 1292da26bd203cbb104291b39891febf7481794f205fJim Ingham ScriptedCommandSynchronicity 1293da26bd203cbb104291b39891febf7481794f205fJim Ingham GetSynchronicity () 1294da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1295da26bd203cbb104291b39891febf7481794f205fJim Ingham return m_synchro; 1296da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1297da26bd203cbb104291b39891febf7481794f205fJim Ingham 12985b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata virtual const char * 12995b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata GetHelpLong () 13005b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata { 13015b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata if (!m_fetched_help_long) 13025b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata { 13035b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter(); 13045b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata if (scripter) 13055b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata { 13065b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata std::string docstring; 13075b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata m_fetched_help_long = scripter->GetDocumentationForItem(m_function_name.c_str(),docstring); 13085b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata if (!docstring.empty()) 13095b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata SetHelpLong(docstring); 13105b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata } 13115b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata } 13125b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata return CommandObjectRaw::GetHelpLong(); 13135b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata } 13145b9f77786d1e9fd356e1fe2d18ce6fcd74977c98Enrico Granata 1315da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 1316da26bd203cbb104291b39891febf7481794f205fJim Ingham virtual bool 1317da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (const char *raw_command_line, CommandReturnObject &result) 13186b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 13196b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter(); 13206b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 13216b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata Error error; 13226b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1323839de396873071d193ed76b0206686af41540962Jim Ingham result.SetStatus(eReturnStatusInvalid); 1324839de396873071d193ed76b0206686af41540962Jim Ingham 13256b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (!scripter || scripter->RunScriptBasedCommand(m_function_name.c_str(), 13266b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata raw_command_line, 13276010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_synchro, 13286b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result, 13296b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata error) == false) 13306b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 13316b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.AppendError(error.AsCString()); 13326b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus(eReturnStatusFailed); 13336b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 13346b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata else 1335839de396873071d193ed76b0206686af41540962Jim Ingham { 1336839de396873071d193ed76b0206686af41540962Jim Ingham // Don't change the status if the command already set it... 1337839de396873071d193ed76b0206686af41540962Jim Ingham if (result.GetStatus() == eReturnStatusInvalid) 1338839de396873071d193ed76b0206686af41540962Jim Ingham { 133926bc105b1882a78de609d46d148ad2b5c4d50656Daniel Malea if (result.GetOutputData() == NULL || result.GetOutputData()[0] == '\0') 1340839de396873071d193ed76b0206686af41540962Jim Ingham result.SetStatus(eReturnStatusSuccessFinishNoResult); 1341839de396873071d193ed76b0206686af41540962Jim Ingham else 1342839de396873071d193ed76b0206686af41540962Jim Ingham result.SetStatus(eReturnStatusSuccessFinishResult); 1343839de396873071d193ed76b0206686af41540962Jim Ingham } 1344839de396873071d193ed76b0206686af41540962Jim Ingham } 13456b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 13466b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return result.Succeeded(); 13476b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 13486b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1349da26bd203cbb104291b39891febf7481794f205fJim Ingham}; 13506010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 1351da26bd203cbb104291b39891febf7481794f205fJim Ingham//------------------------------------------------------------------------- 1352da26bd203cbb104291b39891febf7481794f205fJim Ingham// CommandObjectCommandsScriptImport 1353da26bd203cbb104291b39891febf7481794f205fJim Ingham//------------------------------------------------------------------------- 13546010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 1355da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsScriptImport : public CommandObjectParsed 1356da26bd203cbb104291b39891febf7481794f205fJim Ingham{ 1357da26bd203cbb104291b39891febf7481794f205fJim Inghampublic: 1358da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectCommandsScriptImport (CommandInterpreter &interpreter) : 1359da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectParsed (interpreter, 1360da26bd203cbb104291b39891febf7481794f205fJim Ingham "command script import", 1361da26bd203cbb104291b39891febf7481794f205fJim Ingham "Import a scripting module in LLDB.", 1362da26bd203cbb104291b39891febf7481794f205fJim Ingham NULL), 1363da26bd203cbb104291b39891febf7481794f205fJim Ingham m_options(interpreter) 13646010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 1365da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandArgumentEntry arg1; 1366da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandArgumentData cmd_arg; 1367da26bd203cbb104291b39891febf7481794f205fJim Ingham 1368da26bd203cbb104291b39891febf7481794f205fJim Ingham // Define the first (and only) variant of this arg. 1369da26bd203cbb104291b39891febf7481794f205fJim Ingham cmd_arg.arg_type = eArgTypeFilename; 1370da26bd203cbb104291b39891febf7481794f205fJim Ingham cmd_arg.arg_repetition = eArgRepeatPlain; 1371da26bd203cbb104291b39891febf7481794f205fJim Ingham 1372da26bd203cbb104291b39891febf7481794f205fJim Ingham // There is only one variant this argument could be; put it into the argument entry. 1373da26bd203cbb104291b39891febf7481794f205fJim Ingham arg1.push_back (cmd_arg); 1374da26bd203cbb104291b39891febf7481794f205fJim Ingham 1375da26bd203cbb104291b39891febf7481794f205fJim Ingham // Push the data for the first argument into the m_arguments vector. 1376da26bd203cbb104291b39891febf7481794f205fJim Ingham m_arguments.push_back (arg1); 13776010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata } 1378da26bd203cbb104291b39891febf7481794f205fJim Ingham 1379da26bd203cbb104291b39891febf7481794f205fJim Ingham ~CommandObjectCommandsScriptImport () 13806010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 13816010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata } 1382da26bd203cbb104291b39891febf7481794f205fJim Ingham 138336da2aa6dc5ad9994b638ed09eb81c44cc05540bGreg Clayton virtual int 1384da26bd203cbb104291b39891febf7481794f205fJim Ingham HandleArgumentCompletion (Args &input, 1385da26bd203cbb104291b39891febf7481794f205fJim Ingham int &cursor_index, 1386da26bd203cbb104291b39891febf7481794f205fJim Ingham int &cursor_char_position, 1387da26bd203cbb104291b39891febf7481794f205fJim Ingham OptionElementVector &opt_element_vector, 1388da26bd203cbb104291b39891febf7481794f205fJim Ingham int match_start_point, 1389da26bd203cbb104291b39891febf7481794f205fJim Ingham int max_return_elements, 1390da26bd203cbb104291b39891febf7481794f205fJim Ingham bool &word_complete, 1391da26bd203cbb104291b39891febf7481794f205fJim Ingham StringList &matches) 13926010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 1393da26bd203cbb104291b39891febf7481794f205fJim Ingham std::string completion_str (input.GetArgumentAtIndex(cursor_index)); 1394da26bd203cbb104291b39891febf7481794f205fJim Ingham completion_str.erase (cursor_char_position); 1395da26bd203cbb104291b39891febf7481794f205fJim Ingham 1396da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, 1397da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandCompletions::eDiskFileCompletion, 1398da26bd203cbb104291b39891febf7481794f205fJim Ingham completion_str.c_str(), 1399da26bd203cbb104291b39891febf7481794f205fJim Ingham match_start_point, 1400da26bd203cbb104291b39891febf7481794f205fJim Ingham max_return_elements, 1401da26bd203cbb104291b39891febf7481794f205fJim Ingham NULL, 1402da26bd203cbb104291b39891febf7481794f205fJim Ingham word_complete, 1403da26bd203cbb104291b39891febf7481794f205fJim Ingham matches); 1404da26bd203cbb104291b39891febf7481794f205fJim Ingham return matches.GetSize(); 14056010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata } 14066b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1407da26bd203cbb104291b39891febf7481794f205fJim Ingham virtual Options * 1408da26bd203cbb104291b39891febf7481794f205fJim Ingham GetOptions () 1409da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1410da26bd203cbb104291b39891febf7481794f205fJim Ingham return &m_options; 1411da26bd203cbb104291b39891febf7481794f205fJim Ingham } 141259df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata 1413da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 14146010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14156010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata class CommandOptions : public Options 14166010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 14176010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata public: 14186010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14196010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata CommandOptions (CommandInterpreter &interpreter) : 1420da26bd203cbb104291b39891febf7481794f205fJim Ingham Options (interpreter) 14216010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 14226010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata } 14236010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14246010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata virtual 14256010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata ~CommandOptions (){} 14266010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14276010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata virtual Error 14286010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata SetOptionValue (uint32_t option_idx, const char *option_arg) 14296010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 14306010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata Error error; 14316475c42148a8ea1ca86e5db465db7eca742d897dGreg Clayton const int short_option = m_getopt_table[option_idx].val; 14326010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14336010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata switch (short_option) 14346010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 14356010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata case 'r': 14366010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_allow_reload = true; 14376010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata break; 14386010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata default: 14396010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 14406010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata break; 14416010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata } 14426010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14436010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata return error; 14446010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata } 14456010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14466010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata void 14476010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata OptionParsingStarting () 14486010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 144966068824402d94de2abe81c7e4472a4754572489Enrico Granata m_allow_reload = true; 14506010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata } 14516010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14526010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata const OptionDefinition* 14536010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata GetDefinitions () 14546010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 14556010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata return g_option_table; 14566010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata } 14576010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14586010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata // Options table: Required for subclasses of Options. 14596010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14606010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata static OptionDefinition g_option_table[]; 14616010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14626010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata // Instance variables to hold the values for command options. 14636010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 14646010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata bool m_allow_reload; 14656010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata }; 14666010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 146759df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata bool 1468da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (Args& command, CommandReturnObject &result) 146959df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata { 147059df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata 147159df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata if (m_interpreter.GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) 147259df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata { 147359df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata result.AppendError ("only scripting language supported for module importing is currently Python"); 147459df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata result.SetStatus (eReturnStatusFailed); 147559df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata return false; 147659df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata } 147759df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata 1478da26bd203cbb104291b39891febf7481794f205fJim Ingham size_t argc = command.GetArgumentCount(); 147959df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata 148059df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata if (argc != 1) 148159df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata { 148259df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata result.AppendError ("'command script import' requires one argument"); 148359df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata result.SetStatus (eReturnStatusFailed); 148459df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata return false; 148559df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata } 148659df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata 1487da26bd203cbb104291b39891febf7481794f205fJim Ingham std::string path = command.GetArgumentAtIndex(0); 148859df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata Error error; 148959df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata 14902e7f313dc473b036788319690116b324cb44b765Greg Clayton const bool init_session = true; 149111a8ab60b692eb01b916b1bdcd1725f027ceec5fEnrico Granata // FIXME: this is necessary because CommandObject::CheckRequirements() assumes that 149211a8ab60b692eb01b916b1bdcd1725f027ceec5fEnrico Granata // commands won't ever be recursively invoked, but it's actually possible to craft 149311a8ab60b692eb01b916b1bdcd1725f027ceec5fEnrico Granata // a Python script that does other "command script imports" in __lldb_init_module 149411a8ab60b692eb01b916b1bdcd1725f027ceec5fEnrico Granata // the real fix is to have recursive commands possible with a CommandInvocation object 149511a8ab60b692eb01b916b1bdcd1725f027ceec5fEnrico Granata // separate from the CommandObject itself, so that recursive command invocations 149611a8ab60b692eb01b916b1bdcd1725f027ceec5fEnrico Granata // won't stomp on each other (wrt to execution contents, options, and more) 149711a8ab60b692eb01b916b1bdcd1725f027ceec5fEnrico Granata m_exe_ctx.Clear(); 149859df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata if (m_interpreter.GetScriptInterpreter()->LoadScriptingModule(path.c_str(), 14996010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_options.m_allow_reload, 15002e7f313dc473b036788319690116b324cb44b765Greg Clayton init_session, 150159df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata error)) 150259df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata { 150359df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata result.SetStatus (eReturnStatusSuccessFinishNoResult); 150459df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata } 150559df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata else 150659df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata { 150759df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata result.AppendErrorWithFormat("module importing failed: %s", error.AsCString()); 150859df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata result.SetStatus (eReturnStatusFailed); 150959df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata } 151059df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata 151159df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata return result.Succeeded(); 151259df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata } 15136010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 1514da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandOptions m_options; 15156010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata}; 15166010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 15176010acef0cee54e044d4e7e472ef3d99e13c5045Enrico GranataOptionDefinition 15186010acef0cee54e044d4e7e472ef3d99e13c5045Enrico GranataCommandObjectCommandsScriptImport::CommandOptions::g_option_table[] = 15196010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata{ 152066068824402d94de2abe81c7e4472a4754572489Enrico Granata { LLDB_OPT_SET_1, false, "allow-reload", 'r', no_argument, NULL, 0, eArgTypeNone, "Allow the script to be loaded even if it was already loaded before. This argument exists for backwards compatibility, but reloading is always allowed, whether you specify it or not."}, 15216010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 152259df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata}; 15236b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 15246010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 15256b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 15266b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata// CommandObjectCommandsScriptAdd 15276b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 15286b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1529da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsScriptAdd : public CommandObjectParsed 15306b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata{ 1531da26bd203cbb104291b39891febf7481794f205fJim Inghampublic: 1532da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectCommandsScriptAdd(CommandInterpreter &interpreter) : 1533da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectParsed (interpreter, 1534da26bd203cbb104291b39891febf7481794f205fJim Ingham "command script add", 1535da26bd203cbb104291b39891febf7481794f205fJim Ingham "Add a scripted function as an LLDB command.", 1536da26bd203cbb104291b39891febf7481794f205fJim Ingham NULL), 1537da26bd203cbb104291b39891febf7481794f205fJim Ingham m_options (interpreter) 1538da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1539da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandArgumentEntry arg1; 1540da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandArgumentData cmd_arg; 1541da26bd203cbb104291b39891febf7481794f205fJim Ingham 1542da26bd203cbb104291b39891febf7481794f205fJim Ingham // Define the first (and only) variant of this arg. 1543da26bd203cbb104291b39891febf7481794f205fJim Ingham cmd_arg.arg_type = eArgTypeCommandName; 1544da26bd203cbb104291b39891febf7481794f205fJim Ingham cmd_arg.arg_repetition = eArgRepeatPlain; 1545da26bd203cbb104291b39891febf7481794f205fJim Ingham 1546da26bd203cbb104291b39891febf7481794f205fJim Ingham // There is only one variant this argument could be; put it into the argument entry. 1547da26bd203cbb104291b39891febf7481794f205fJim Ingham arg1.push_back (cmd_arg); 1548da26bd203cbb104291b39891febf7481794f205fJim Ingham 1549da26bd203cbb104291b39891febf7481794f205fJim Ingham // Push the data for the first argument into the m_arguments vector. 1550da26bd203cbb104291b39891febf7481794f205fJim Ingham m_arguments.push_back (arg1); 1551da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1552da26bd203cbb104291b39891febf7481794f205fJim Ingham 1553da26bd203cbb104291b39891febf7481794f205fJim Ingham ~CommandObjectCommandsScriptAdd () 1554da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1555da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1556da26bd203cbb104291b39891febf7481794f205fJim Ingham 1557da26bd203cbb104291b39891febf7481794f205fJim Ingham virtual Options * 1558da26bd203cbb104291b39891febf7481794f205fJim Ingham GetOptions () 1559da26bd203cbb104291b39891febf7481794f205fJim Ingham { 1560da26bd203cbb104291b39891febf7481794f205fJim Ingham return &m_options; 1561da26bd203cbb104291b39891febf7481794f205fJim Ingham } 1562da26bd203cbb104291b39891febf7481794f205fJim Ingham 1563da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 15646b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 15656b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata class CommandOptions : public Options 15666b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 15676b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata public: 15686b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 15696b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandOptions (CommandInterpreter &interpreter) : 15706b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata Options (interpreter) 15716b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 15726b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 15736b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 15746b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual 15756b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata ~CommandOptions (){} 15766b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 15776b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual Error 15786b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata SetOptionValue (uint32_t option_idx, const char *option_arg) 15796b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 15806b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata Error error; 15816475c42148a8ea1ca86e5db465db7eca742d897dGreg Clayton const int short_option = m_getopt_table[option_idx].val; 15826b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 15836b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata switch (short_option) 15846b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 15856b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata case 'f': 15866b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_funct_name = std::string(option_arg); 15876b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata break; 15886010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata case 's': 15896010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_synchronous = (ScriptedCommandSynchronicity) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); 15906010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata if (!error.Success()) 15916010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata error.SetErrorStringWithFormat ("unrecognized value for synchronicity '%s'", option_arg); 15926010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata break; 15936b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata default: 15949c236733d43e6250c8a5671a438f4a2afeb9c0b2Greg Clayton error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 15956b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata break; 15966b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 15976b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 15986b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return error; 15996b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16006b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 16016b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata void 16026b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata OptionParsingStarting () 16036b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16046b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_funct_name = ""; 16056010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_synchronous = eScriptedCommandSynchronicitySynchronous; 16066b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16076b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 16086b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata const OptionDefinition* 16096b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata GetDefinitions () 16106b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16116b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return g_option_table; 16126b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16136b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 16146b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata // Options table: Required for subclasses of Options. 16156b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 16166b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata static OptionDefinition g_option_table[]; 16176b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 16186b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata // Instance variables to hold the values for command options. 16196b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 16206b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata std::string m_funct_name; 16216010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata ScriptedCommandSynchronicity m_synchronous; 16226b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata }; 1623da26bd203cbb104291b39891febf7481794f205fJim Ingham 1624da26bd203cbb104291b39891febf7481794f205fJim Inghamprivate: 16256b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata class PythonAliasReader : public InputReaderEZ 16266b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16276b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata private: 16286b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandInterpreter& m_interpreter; 16296b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata std::string m_cmd_name; 16306010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata ScriptedCommandSynchronicity m_synchronous; 16316b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata StringList m_user_input; 16326b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata DISALLOW_COPY_AND_ASSIGN (PythonAliasReader); 16336b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata public: 16346b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata PythonAliasReader(Debugger& debugger, 16356b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandInterpreter& interpreter, 16366010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata std::string cmd_name, 16376010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata ScriptedCommandSynchronicity synch) : 16386b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata InputReaderEZ(debugger), 16396b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_interpreter(interpreter), 16406b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_cmd_name(cmd_name), 16416010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_synchronous(synch), 16426b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_user_input() 16436b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata {} 16446b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 16456b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual 16466b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata ~PythonAliasReader() 16476b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16486b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16496b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 16506b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual void ActivateHandler(HandlerData& data) 16516b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16526b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata StreamSP out_stream = data.GetOutStream(); 16536b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata bool batch_mode = data.GetBatchMode(); 16546b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (!batch_mode) 16556b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16566b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Printf ("%s\n", g_python_command_instructions); 16576b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (data.reader.GetPrompt()) 16586b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Printf ("%s", data.reader.GetPrompt()); 16596b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Flush(); 16606b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16616b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16626b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 16636b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual void ReactivateHandler(HandlerData& data) 16646b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16656b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata StreamSP out_stream = data.GetOutStream(); 16666b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata bool batch_mode = data.GetBatchMode(); 16676b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (data.reader.GetPrompt() && !batch_mode) 16686b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16696b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Printf ("%s", data.reader.GetPrompt()); 16706b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Flush(); 16716b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16726b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16736b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual void GotTokenHandler(HandlerData& data) 16746b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16756b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata StreamSP out_stream = data.GetOutStream(); 16766b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata bool batch_mode = data.GetBatchMode(); 16776b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (data.bytes && data.bytes_len) 16786b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16796b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_user_input.AppendString(data.bytes, data.bytes_len); 16806b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16816b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (!data.reader.IsDone() && data.reader.GetPrompt() && !batch_mode) 16826b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16836b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Printf ("%s", data.reader.GetPrompt()); 16846b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Flush(); 16856b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16866b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16876b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual void InterruptHandler(HandlerData& data) 16886b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16896b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata StreamSP out_stream = data.GetOutStream(); 16906b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata bool batch_mode = data.GetBatchMode(); 16916b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata data.reader.SetIsDone (true); 16926b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (!batch_mode) 16936b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 16946010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata out_stream->Printf ("Warning: No script attached.\n"); 16956b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Flush(); 16966b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16976b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 16986b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual void EOFHandler(HandlerData& data) 16996b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17006b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata data.reader.SetIsDone (true); 17016b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17026b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata virtual void DoneHandler(HandlerData& data) 17036b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17046b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata StreamSP out_stream = data.GetOutStream(); 17056b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 17066b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata ScriptInterpreter *interpreter = data.reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); 17076b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (!interpreter) 17086b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17096010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata out_stream->Printf ("Script interpreter missing: no script attached.\n"); 17106b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Flush(); 17116b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return; 17126b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 1713400105dd92731a0c8968d6296b0b7279b483ebf0Enrico Granata std::string funct_name_str; 17146b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (!interpreter->GenerateScriptAliasFunction (m_user_input, 1715400105dd92731a0c8968d6296b0b7279b483ebf0Enrico Granata funct_name_str)) 17166b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17176010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata out_stream->Printf ("Unable to create function: no script attached.\n"); 17186b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Flush(); 17196b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return; 17206b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 1721400105dd92731a0c8968d6296b0b7279b483ebf0Enrico Granata if (funct_name_str.empty()) 17226b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17236010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata out_stream->Printf ("Unable to obtain a function name: no script attached.\n"); 17246b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Flush(); 17256b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return; 17266b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17276b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata // everything should be fine now, let's add this alias 17286b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 17296b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandObjectSP command_obj_sp(new CommandObjectPythonFunction(m_interpreter, 17306b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_cmd_name, 1731400105dd92731a0c8968d6296b0b7279b483ebf0Enrico Granata funct_name_str.c_str(), 17326010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_synchronous)); 17336b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 17346010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata if (!m_interpreter.AddUserCommand(m_cmd_name, command_obj_sp, true)) 17356b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17366010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata out_stream->Printf ("Unable to add selected command: no script attached.\n"); 17376b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata out_stream->Flush(); 17386b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return; 17396b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17406b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17416b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata }; 17426b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1743da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 17446b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata bool 1745da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (Args& command, CommandReturnObject &result) 17466b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 1747e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata 1748e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata if (m_interpreter.GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) 1749e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata { 1750e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata result.AppendError ("only scripting language supported for scripted commands is currently Python"); 1751e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata result.SetStatus (eReturnStatusFailed); 1752e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata return false; 1753e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata } 1754e5e34cb15f031237004b05abfa623c71f879f6c0Enrico Granata 1755da26bd203cbb104291b39891febf7481794f205fJim Ingham size_t argc = command.GetArgumentCount(); 17566b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 17576b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (argc != 1) 17586b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17596b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.AppendError ("'command script add' requires one argument"); 17606b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusFailed); 17616b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return false; 17626b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17636b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1764da26bd203cbb104291b39891febf7481794f205fJim Ingham std::string cmd_name = command.GetArgumentAtIndex(0); 17656b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 17666b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (m_options.m_funct_name.empty()) 17676b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17686b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata InputReaderSP reader_sp (new PythonAliasReader (m_interpreter.GetDebugger(), 17696b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_interpreter, 17706010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata cmd_name, 17716010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_options.m_synchronous)); 17726b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 17736b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (reader_sp) 17746b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17756b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 17766b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata InputReaderEZ::InitializationParameters ipr; 17776b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 17786b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata Error err (reader_sp->Initialize (ipr.SetBaton(NULL).SetPrompt(" "))); 17796b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (err.Success()) 17806b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17816b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_interpreter.GetDebugger().PushInputReader (reader_sp); 17826b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusSuccessFinishNoResult); 17836b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17846b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata else 17856b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17866b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.AppendError (err.AsCString()); 17876b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusFailed); 17886b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17896b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17906b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata else 17916b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17926b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.AppendError("out of memory"); 17936b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusFailed); 17946b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17956b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 17966b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata else 17976b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 17986010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata CommandObjectSP new_cmd(new CommandObjectPythonFunction(m_interpreter, 17996010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata cmd_name, 18006010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_options.m_funct_name, 18016010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata m_options.m_synchronous)); 18026010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata if (m_interpreter.AddUserCommand(cmd_name, new_cmd, true)) 18036b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 18046b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusSuccessFinishNoResult); 18056b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 18066b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata else 18076b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 18086b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.AppendError("cannot add command"); 18096b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusFailed); 18106b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 18116b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 18126b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18136b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return result.Succeeded(); 18146b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18156b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 1816da26bd203cbb104291b39891febf7481794f205fJim Ingham 1817da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandOptions m_options; 18186b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata}; 18196b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18206010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granatastatic OptionEnumValueElement g_script_synchro_type[] = 18216010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata{ 18226010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { eScriptedCommandSynchronicitySynchronous, "synchronous", "Run synchronous"}, 18236010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { eScriptedCommandSynchronicityAsynchronous, "asynchronous", "Run asynchronous"}, 18246010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { eScriptedCommandSynchronicityCurrentValue, "current", "Do not alter current setting"}, 18256010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { 0, NULL, NULL } 18266010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata}; 18276010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 18286b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico GranataOptionDefinition 18296b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico GranataCommandObjectCommandsScriptAdd::CommandOptions::g_option_table[] = 18306b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata{ 1831915448044bac6fdac22a33cc46697dcb771a8df2Enrico Granata { LLDB_OPT_SET_1, false, "function", 'f', required_argument, NULL, 0, eArgTypePythonFunction, "Name of the Python function to bind to this command name."}, 18326010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata { LLDB_OPT_SET_1, false, "synchronicity", 's', required_argument, g_script_synchro_type, 0, eArgTypeScriptedCommandSynchronicity, "Set the synchronicity of this command's executions with regard to LLDB event system."}, 18336b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } 18346b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata}; 18356b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18366b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 18376b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata// CommandObjectCommandsScriptList 18386b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 18396b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1840da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsScriptList : public CommandObjectParsed 18416b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata{ 18426b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granataprivate: 18436010acef0cee54e044d4e7e472ef3d99e13c5045Enrico Granata 18446b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granatapublic: 18456b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandObjectCommandsScriptList(CommandInterpreter &interpreter) : 1846da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectParsed (interpreter, 18476b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata "command script list", 18486b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata "List defined scripted commands.", 18496b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata NULL) 18506b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 18516b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 18526b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18536b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata ~CommandObjectCommandsScriptList () 18546b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 18556b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 18566b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18576b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata bool 1858da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (Args& command, CommandReturnObject &result) 18596b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 18606b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18616b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_interpreter.GetHelp(result, 18626b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandInterpreter::eCommandTypesUserDef); 18636b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18646b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusSuccessFinishResult); 18656b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18666b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return true; 18676b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18686b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18696b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 18706b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata}; 18716b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18726b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 18736b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata// CommandObjectCommandsScriptClear 18746b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 18756b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1876da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsScriptClear : public CommandObjectParsed 18776b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata{ 18786b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granataprivate: 18796b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18806b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granatapublic: 18816b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandObjectCommandsScriptClear(CommandInterpreter &interpreter) : 1882da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectParsed (interpreter, 1883da26bd203cbb104291b39891febf7481794f205fJim Ingham "command script clear", 1884da26bd203cbb104291b39891febf7481794f205fJim Ingham "Delete all scripted commands.", 1885da26bd203cbb104291b39891febf7481794f205fJim Ingham NULL) 18866b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 18876b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 18886b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18896b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata ~CommandObjectCommandsScriptClear () 18906b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 18916b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 18926b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1893da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 18946b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata bool 1895da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (Args& command, CommandReturnObject &result) 18966b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 18976b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 18986b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_interpreter.RemoveAllUser(); 18996b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19006b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusSuccessFinishResult); 19016b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19026b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return true; 19036b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 19046b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata}; 19056b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19066b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 19076b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata// CommandObjectCommandsScriptDelete 19086b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 19096b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1910da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectCommandsScriptDelete : public CommandObjectParsed 19116b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata{ 19126b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granatapublic: 19136b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandObjectCommandsScriptDelete(CommandInterpreter &interpreter) : 1914da26bd203cbb104291b39891febf7481794f205fJim Ingham CommandObjectParsed (interpreter, 1915da26bd203cbb104291b39891febf7481794f205fJim Ingham "command script delete", 1916da26bd203cbb104291b39891febf7481794f205fJim Ingham "Delete a scripted command.", 1917da26bd203cbb104291b39891febf7481794f205fJim Ingham NULL) 19186b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 19196b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandArgumentEntry arg1; 19206b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandArgumentData cmd_arg; 19216b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19226b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata // Define the first (and only) variant of this arg. 19236b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata cmd_arg.arg_type = eArgTypeCommandName; 19246b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata cmd_arg.arg_repetition = eArgRepeatPlain; 19256b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19266b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata // There is only one variant this argument could be; put it into the argument entry. 19276b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata arg1.push_back (cmd_arg); 19286b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19296b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata // Push the data for the first argument into the m_arguments vector. 19306b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_arguments.push_back (arg1); 19316b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 19326b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19336b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata ~CommandObjectCommandsScriptDelete () 19346b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 19356b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 19366b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1937da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected: 19386b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata bool 1939da26bd203cbb104291b39891febf7481794f205fJim Ingham DoExecute (Args& command, CommandReturnObject &result) 19406b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 19416b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1942da26bd203cbb104291b39891febf7481794f205fJim Ingham size_t argc = command.GetArgumentCount(); 19436b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19446b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (argc != 1) 19456b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 19466b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.AppendError ("'command script delete' requires one argument"); 19476b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusFailed); 19486b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return false; 19496b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 19506b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1951da26bd203cbb104291b39891febf7481794f205fJim Ingham const char* cmd_name = command.GetArgumentAtIndex(0); 19526b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19536b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata if (cmd_name && *cmd_name && m_interpreter.HasUserCommands() && m_interpreter.UserCommandExists(cmd_name)) 19546b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 19556b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata m_interpreter.RemoveUser(cmd_name); 19566b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusSuccessFinishResult); 19576b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 19586b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata else 19596b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 19606b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.AppendErrorWithFormat ("command %s not found", cmd_name); 19616b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata result.SetStatus (eReturnStatusFailed); 19626b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 19636b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19646b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata return result.Succeeded(); 19656b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19666b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 19676b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata}; 19686b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19696b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata#pragma mark CommandObjectMultiwordCommandsScript 19706b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19716b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 19726b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata// CommandObjectMultiwordCommandsScript 19736b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata//------------------------------------------------------------------------- 19746b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19756b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granataclass CommandObjectMultiwordCommandsScript : public CommandObjectMultiword 19766b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata{ 19776b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granatapublic: 19786b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandObjectMultiwordCommandsScript (CommandInterpreter &interpreter) : 19796b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata CommandObjectMultiword (interpreter, 19806b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata "command script", 19816b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata "A set of commands for managing or customizing script commands.", 19826b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata "command script <subcommand> [<subcommand-options>]") 19836b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 19846b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata LoadSubCommand ("add", CommandObjectSP (new CommandObjectCommandsScriptAdd (interpreter))); 19856b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata LoadSubCommand ("delete", CommandObjectSP (new CommandObjectCommandsScriptDelete (interpreter))); 19866b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata LoadSubCommand ("clear", CommandObjectSP (new CommandObjectCommandsScriptClear (interpreter))); 19876b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata LoadSubCommand ("list", CommandObjectSP (new CommandObjectCommandsScriptList (interpreter))); 198859df36f99b76e33852e6848a162f5c2851074ea2Enrico Granata LoadSubCommand ("import", CommandObjectSP (new CommandObjectCommandsScriptImport (interpreter))); 19896b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 19906b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19916b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata ~CommandObjectMultiwordCommandsScript () 19926b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata { 19936b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata } 19946b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19956b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata}; 19966b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 19976b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata 1998767af88aa617288e584afcfed055f7755e408542Jim Ingham#pragma mark CommandObjectMultiwordCommands 1999767af88aa617288e584afcfed055f7755e408542Jim Ingham 2000767af88aa617288e584afcfed055f7755e408542Jim Ingham//------------------------------------------------------------------------- 2001767af88aa617288e584afcfed055f7755e408542Jim Ingham// CommandObjectMultiwordCommands 2002767af88aa617288e584afcfed055f7755e408542Jim Ingham//------------------------------------------------------------------------- 2003767af88aa617288e584afcfed055f7755e408542Jim Ingham 2004767af88aa617288e584afcfed055f7755e408542Jim InghamCommandObjectMultiwordCommands::CommandObjectMultiwordCommands (CommandInterpreter &interpreter) : 2005238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton CommandObjectMultiword (interpreter, 200640e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton "command", 2007c1ad82eb979ee856b86aec6e2acb7bddf75f7c4fCaroline Tice "A set of commands for managing or customizing the debugger commands.", 200840e482434007a7cac49fb1f437fe7d13db2cf523Greg Clayton "command <subcommand> [<subcommand-options>]") 2009767af88aa617288e584afcfed055f7755e408542Jim Ingham{ 2010238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton LoadSubCommand ("source", CommandObjectSP (new CommandObjectCommandsSource (interpreter))); 2011238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton LoadSubCommand ("alias", CommandObjectSP (new CommandObjectCommandsAlias (interpreter))); 2012238c0a1e7b733cee539258faa656159c63f9e893Greg Clayton LoadSubCommand ("unalias", CommandObjectSP (new CommandObjectCommandsUnalias (interpreter))); 2013d12aeab33bab559e138307f599077da3918a3238Greg Clayton LoadSubCommand ("regex", CommandObjectSP (new CommandObjectCommandsAddRegex (interpreter))); 20146247dbee41ec51e9a082df7e86269c0f47f28160Jim Ingham LoadSubCommand ("history", CommandObjectSP (new CommandObjectCommandsHistory (interpreter))); 20156b1596d81c34c6efb10ed51a3572d6b145b73f5bEnrico Granata LoadSubCommand ("script", CommandObjectSP (new CommandObjectMultiwordCommandsScript (interpreter))); 2016767af88aa617288e584afcfed055f7755e408542Jim Ingham} 2017767af88aa617288e584afcfed055f7755e408542Jim Ingham 2018767af88aa617288e584afcfed055f7755e408542Jim InghamCommandObjectMultiwordCommands::~CommandObjectMultiwordCommands () 2019767af88aa617288e584afcfed055f7755e408542Jim Ingham{ 2020767af88aa617288e584afcfed055f7755e408542Jim Ingham} 2021767af88aa617288e584afcfed055f7755e408542Jim Ingham 2022