Coverage Report

Created: 2024-03-28 05:31

/src/bloaty/src/util.cc
Line
Count
Source
1
// Copyright 2016 Google Inc. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include "util.h"
16
17
using absl::string_view;
18
19
namespace bloaty {
20
21
ABSL_ATTRIBUTE_NORETURN
22
17.9M
void Throw(const char *str, int line) {
23
17.9M
  throw bloaty::Error(str, __FILE__, line);
24
17.9M
}
25
26
1.07M
absl::string_view ReadNullTerminated(absl::string_view* data) {
27
1.07M
  const char* nullz =
28
1.07M
      static_cast<const char*>(memchr(data->data(), '\0', data->size()));
29
30
  // Return false if not NULL-terminated.
31
1.07M
  if (nullz == NULL) {
32
551
    THROW("DWARF string was not NULL-terminated");
33
551
  }
34
35
1.06M
  size_t len = nullz - data->data();
36
1.06M
  absl::string_view val = data->substr(0, len);
37
1.06M
  data->remove_prefix(len + 1);  // Remove NULL also.
38
1.06M
  return val;
39
1.07M
}
40
41
}  // namespace bloaty