2011-04-28 06:04:39 +08:00
|
|
|
//===-- OptionGroupFormat.cpp -----------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-05-14 04:21:08 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupFormat.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2011-09-10 08:48:33 +08:00
|
|
|
#include "lldb/Utility/Utils.h"
|
2011-04-28 06:04:39 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
OptionGroupFormat::OptionGroupFormat (lldb::Format default_format,
|
|
|
|
uint64_t default_byte_size,
|
|
|
|
uint64_t default_count) :
|
|
|
|
m_format (default_format, default_format),
|
|
|
|
m_byte_size (default_byte_size, default_byte_size),
|
|
|
|
m_count (default_count, default_count)
|
2011-04-28 06:04:39 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionGroupFormat::~OptionGroupFormat ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static OptionDefinition
|
|
|
|
g_option_table[] =
|
|
|
|
{
|
2011-10-25 14:44:01 +08:00
|
|
|
{ LLDB_OPT_SET_1, false, "format",'f', required_argument, NULL, 0, eArgTypeFormat , "Specify a format to be used for display."},
|
|
|
|
{ LLDB_OPT_SET_2, false, "size" ,'s', required_argument, NULL, 0, eArgTypeByteSize, "The size in bytes to use when displaying with the selected format."},
|
|
|
|
{ LLDB_OPT_SET_3, false, "count" ,'c', required_argument, NULL, 0, eArgTypeCount , "The number of total items to display."},
|
2011-04-28 06:04:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
OptionGroupFormat::GetNumDefinitions ()
|
|
|
|
{
|
2011-10-25 14:44:01 +08:00
|
|
|
if (m_byte_size.GetDefaultValue() < UINT64_MAX)
|
|
|
|
{
|
|
|
|
if (m_count.GetDefaultValue() < UINT64_MAX)
|
|
|
|
return 3;
|
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 1;
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const OptionDefinition *
|
|
|
|
OptionGroupFormat::GetDefinitions ()
|
|
|
|
{
|
|
|
|
return g_option_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter,
|
2011-04-29 04:55:26 +08:00
|
|
|
uint32_t option_idx,
|
|
|
|
const char *option_arg)
|
2011-04-28 06:04:39 +08:00
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
char short_option = (char) g_option_table[option_idx].short_option;
|
|
|
|
|
|
|
|
switch (short_option)
|
|
|
|
{
|
|
|
|
case 'f':
|
|
|
|
error = m_format.SetValueFromCString (option_arg);
|
|
|
|
break;
|
|
|
|
|
2011-10-25 14:44:01 +08:00
|
|
|
case 'c':
|
|
|
|
if (m_count.GetDefaultValue() == 0)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("--count option is disabled");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error = m_count.SetValueFromCString (option_arg);
|
|
|
|
if (m_count.GetCurrentValue() == 0)
|
|
|
|
error.SetErrorStringWithFormat("invalid --count option value '%s'", option_arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
if (m_byte_size.GetDefaultValue() == 0)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("--size option is disabled");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error = m_byte_size.SetValueFromCString (option_arg);
|
|
|
|
if (m_byte_size.GetCurrentValue() == 0)
|
|
|
|
error.SetErrorStringWithFormat("invalid --size option value '%s'", option_arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
default:
|
|
|
|
error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OptionGroupFormat::OptionParsingStarting (CommandInterpreter &interpreter)
|
|
|
|
{
|
|
|
|
m_format.Clear();
|
2011-10-25 14:44:01 +08:00
|
|
|
m_byte_size.Clear();
|
|
|
|
m_count.Clear();
|
2011-04-28 06:04:39 +08:00
|
|
|
}
|