[Lldb-commits] [PATCH] D24952: Remove Args::m_argv

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 26 22:16:55 PDT 2016


zturner created this revision.
zturner added a reviewer: clayborg.
zturner added subscribers: lldb-commits, LLDB.

The `Args` class was trying to maintain two parallel argument vectors.  One that owned the memory and contained `std::strings`, and one that contained `const char *`'s that could be used similar to how `argv` is used.

But dealing with pointers to pointers is unsafe and should be avoided wherever possible.  Furthermore, there doesn't seem to be much point in maintaining a second copy of the array, as it only serves to complicate the parsing logic since the two have to be kept in sync with each other, and really, the master copy has everything you need, including the null terminated strings.

So I removed `m_argv` entirely.  The `Args` class will also no longer vend a `const char**`, and instead you can pass it a `std::vector<const char*>&` and it will fill it with null terminated argument strings.  This can be used exactly like a `const char**` by writing `&args[0]`, but now you have to explicitly opt into this, and by default you just get a nice safe container that can be used for example in ranged based fors.  And the logic is simplified as well since the two arrays don't have to be kept in sync with each other.

All tests pass on Windows.

https://reviews.llvm.org/D24952

Files:
  examples/plugins/commands/fooplugin.cpp
  include/lldb/API/SBCommandInterpreter.h
  include/lldb/Host/FileSpec.h
  include/lldb/Host/OptionParser.h
  include/lldb/Interpreter/Args.h
  source/API/SBCommandInterpreter.cpp
  source/API/SBLaunchInfo.cpp
  source/API/SBProcess.cpp
  source/API/SBTarget.cpp
  source/Commands/CommandObjectBreakpoint.cpp
  source/Commands/CommandObjectLog.cpp
  source/Host/common/FileSpec.cpp
  source/Host/common/OptionParser.cpp
  source/Interpreter/Args.cpp
  source/Interpreter/CommandInterpreter.cpp
  source/Interpreter/CommandObject.cpp
  source/Interpreter/OptionValueArgs.cpp
  source/Interpreter/OptionValueArray.cpp
  source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  source/Target/ProcessInfo.cpp
  source/Target/ProcessLaunchInfo.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24952.72601.patch
Type: text/x-patch
Size: 56381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160927/a5beab5a/attachment-0001.bin>


More information about the lldb-commits mailing list