libcsdbg  1.28
C++ exception (and generic) stack trace debug library
void csdbg::util::init ( i32 argc,
i8 **  argv 
)
static

Initialize the library runtime configuration. Seek command line arguments that are related with libcsdbg (prefixed with –csdbg-) and move them from the argument vector to the runtime configuration list (util::m_config)

Parameters
[in,out]argcthe argument count
[in,out]argvthe argument vector
Note
If an exception occurs, the process exits

Definition at line 188 of file util.cpp.

References __D_ASSERT, csdbg::chain< T >::add(), csdbg::chain< T >::at(), csdbg::string::cstr(), dbg_info(), likely, m_config, csdbg::chain< T >::size(), and unlikely.

189 {
190  __D_ASSERT(argc >= 1);
191  __D_ASSERT(argv != NULL);
192  if ( unlikely(argc <= 1 || argv == NULL) )
193  return;
194 
195  try {
196  for (i32 i = 0; likely(i < argc); i++) {
197  i8 *arg = argv[i];
198 
199  /* If the argument is not libcsdbg-related */
200  if ( likely(strstr(arg, "--csdbg-") != arg) )
201  continue;
202 
203  if ( likely(strlen(arg) > 8) )
204  m_config->add(new string(arg + 8));
205 
206  /* Remove it from the argument vector */
207  for (i32 j = i; likely(j < argc); j++)
208  argv[j] = argv[j + 1];
209 
210  i--;
211  argc--;
212  }
213 
214 #if CSDBG_DBG_LEVEL & CSDBG_DBGL_INFO
215  if ( unlikely(m_config->size() > 0) )
216  util::dbg_info("libcsdbg runtime configuration:");
217 
218  for (u32 i = 0, sz = m_config->size(); likely(i < sz); i++)
219  util::dbg_info(" arg %d: --csdbg-(%s)", i, m_config->at(i)->cstr());
220 #endif
221 
222  return;
223  }
224 
225  catch (exception &x) {
226  std::cerr << x;
227  }
228 
229  catch (std::exception &x) {
230  std::cerr << x;
231  }
232 
233  exit(EXIT_FAILURE);
234 }
virtual T * at(u32) const
Get the node data pointer at a chain offset.
Definition: chain.hpp:440
virtual u32 size() const
Get the chain size (node count)
Definition: chain.hpp:276
char i8
8-bit signed integer
Definition: config.hpp:72
static u32 argc()
Get the number of CLI arguments.
Definition: util.cpp:242
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
static chain< string > * m_config
Runtime configuration.
Definition: util.hpp:28
virtual const i8 * cstr() const
Get the C-string equivalent.
Definition: string.cpp:211
virtual chain & add(T *)
Add a node to the chain.
Definition: chain.hpp:363
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
int i32
32-bit signed integer
Definition: config.hpp:82
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349
static void dbg_info(const i8 *,...)
Print an informational debug message on the standard error stream.
Definition: util.cpp:680
static const string * argv(u32)
Get a CLI argument, given its offset in util::m_config.
Definition: util.cpp:259
#define __D_ASSERT(x)
Assertion macro.
Definition: config.hpp:268

+ Here is the call graph for this function: