LCOV - code coverage report
Current view: directory - src/trusted/debug_stub - util.cc (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 46 39 84.8 %
Date: 2014-07-02 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright 2010 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can
       4                 :  * be found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : #include <stdio.h>
       8                 : #include <stdlib.h>
       9                 : #include <stdarg.h>
      10                 : #include <string.h>
      11                 : 
      12                 : #include <string>
      13                 : #include <vector>
      14                 : 
      15                 : #include "native_client/src/trusted/debug_stub/util.h"
      16                 : 
      17                 : using std::string;
      18                 : 
      19                 : namespace gdb_rsp {
      20                 : 
      21            8485 : bool NibbleToInt(char ch, int *val) {
      22                 :   // Check for nibble of a-f
      23            8485 :   if ((ch >= 'a') && (ch <= 'f')) {
      24            1512 :     if (val) *val = (ch - 'a' + 10);
      25            1512 :     return true;
      26                 :   }
      27                 : 
      28                 :   // Check for nibble of A-F
      29            6973 :   if ((ch >= 'A') && (ch <= 'F')) {
      30               6 :     if (val) *val = (ch - 'A' + 10);
      31               6 :     return true;
      32                 :   }
      33                 : 
      34                 :   // Check for nibble of 0-9
      35            6967 :   if ((ch >= '0') && (ch <= '9')) {
      36            5393 :     if (val) *val = (ch - '0');
      37            5393 :     return true;
      38                 :   }
      39                 : 
      40                 :   // Not a valid nibble representation
      41            1574 :   return false;
      42                 : }
      43                 : 
      44           24998 : bool IntToNibble(int nibble, char *ch) {
      45                 :   // Verify this value fits in a nibble
      46           24998 :   if (nibble != (nibble & 0xF)) return false;
      47                 : 
      48           24502 :   nibble &= 0xF;
      49           24502 :   if (nibble < 10) {
      50           19574 :     if (ch) *ch =  '0' + nibble;
      51                 :   } else {
      52                 :     // Although uppercase maybe more readible GDB
      53                 :     // expects lower case values.
      54            4928 :     if (ch) *ch = 'a' + (nibble - 10);
      55                 :   }
      56                 : 
      57           24502 :   return true;
      58                 : }
      59                 : 
      60               0 : bool NibblesToByte(const char *inStr, int *outInt) {
      61                 :   int o1, o2;
      62                 : 
      63               0 :   if (NibbleToInt(inStr[0], &o1) && NibbleToInt(inStr[1], &o2)) {
      64               0 :     *outInt = (o1 << 4) + o2;
      65               0 :     return true;
      66                 :   }
      67                 : 
      68               0 :   return false;
      69                 : }
      70                 : 
      71             209 : stringvec StringSplit(const string &instr, const char *delim) {
      72             209 :   int count = 0;
      73             209 :   const char *in = instr.data();
      74             209 :   const char *start = in;
      75                 : 
      76             209 :   stringvec ovec;
      77                 : 
      78                 :   // Check if we have nothing to do
      79             209 :   if (NULL == in) return ovec;
      80             209 :   if (NULL == delim) {
      81               0 :     ovec.push_back(string(in));
      82               0 :     return ovec;
      83                 :   }
      84                 : 
      85             888 :   while (*in) {
      86             470 :     int len = 0;
      87                 :     // Toss all preceeding delimiters
      88             470 :     while (*in && strchr(delim, *in)) in++;
      89                 : 
      90                 :     // If we still have something to process
      91             470 :     if (*in) {
      92             441 :       std::string token;
      93             441 :       start = in;
      94             441 :       len   = 0;
      95                 :       // Keep moving forward for all valid chars
      96            4259 :       while (*in && (strchr(delim, *in) == NULL)) {
      97            3377 :         len++;
      98            3377 :         in++;
      99                 :       }
     100                 : 
     101                 :       // Build this token and add it to the array.
     102             441 :       ovec.resize(count + 1);
     103             441 :       ovec[count].assign(start, len);
     104             441 :       count++;
     105                 :     }
     106                 :   }
     107                 : 
     108             209 :   return ovec;
     109                 : }
     110                 : 
     111                 : 
     112                 : 
     113                 : }  // End of namespace gdb_rsp
     114                 : 

Generated by: LCOV version 1.7