Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmBinUtilsLinuxELFObjdumpGetRuntimeDependenciesTool.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
4
#include "cmBinUtilsLinuxELFObjdumpGetRuntimeDependenciesTool.h"
5
6
#include <istream>
7
#include <vector>
8
9
#include <cmsys/RegularExpression.hxx>
10
11
#include "cmRuntimeDependencyArchive.h"
12
#include "cmStringAlgorithms.h"
13
#include "cmSystemTools.h"
14
#include "cmUVProcessChain.h"
15
#include "cmUVStream.h"
16
17
cmBinUtilsLinuxELFObjdumpGetRuntimeDependenciesTool::
18
  cmBinUtilsLinuxELFObjdumpGetRuntimeDependenciesTool(
19
    cmRuntimeDependencyArchive* archive)
20
0
  : cmBinUtilsLinuxELFGetRuntimeDependenciesTool(archive)
21
0
{
22
0
}
23
24
bool cmBinUtilsLinuxELFObjdumpGetRuntimeDependenciesTool::GetFileInfo(
25
  std::string const& file, std::vector<std::string>& needed,
26
  std::vector<std::string>& rpaths, std::vector<std::string>& runpaths)
27
0
{
28
0
  cmUVProcessChainBuilder builder;
29
0
  builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT);
30
31
0
  std::vector<std::string> command;
32
0
  if (!this->Archive->GetGetRuntimeDependenciesCommand("objdump", command)) {
33
0
    this->SetError("Could not find objdump");
34
0
    return false;
35
0
  }
36
0
  command.emplace_back("-p");
37
0
  command.push_back(file);
38
0
  builder.AddCommand(command);
39
40
0
  auto process = builder.Start();
41
0
  if (!process.Valid() || process.GetStatus(0).SpawnResult != 0) {
42
0
    this->SetError(cmStrCat("Failed to start objdump process for:\n  ", file));
43
0
    return false;
44
0
  }
45
46
0
  std::string line;
47
0
  static cmsys::RegularExpression const neededRegex("^ *NEEDED *([^\n]*)$");
48
0
  static cmsys::RegularExpression const rpathRegex("^ *RPATH *([^\n]*)$");
49
0
  static cmsys::RegularExpression const runpathRegex("^ *RUNPATH *([^\n]*)$");
50
0
  cmUVIStream output(process.OutputStream());
51
0
  while (std::getline(output, line)) {
52
0
    cmsys::RegularExpressionMatch match;
53
0
    if (neededRegex.find(line.c_str(), match)) {
54
0
      needed.push_back(match.match(1));
55
0
    } else if (rpathRegex.find(line.c_str(), match)) {
56
0
      std::vector<std::string> rpathSplit =
57
0
        cmSystemTools::SplitString(match.match(1), ':');
58
0
      rpaths.reserve(rpaths.size() + rpathSplit.size());
59
0
      for (auto const& rpath : rpathSplit) {
60
0
        rpaths.push_back(rpath);
61
0
      }
62
0
    } else if (runpathRegex.find(line.c_str(), match)) {
63
0
      std::vector<std::string> runpathSplit =
64
0
        cmSystemTools::SplitString(match.match(1), ':');
65
0
      runpaths.reserve(runpaths.size() + runpathSplit.size());
66
0
      for (auto const& runpath : runpathSplit) {
67
0
        runpaths.push_back(runpath);
68
0
      }
69
0
    }
70
0
  }
71
72
0
  if (!process.Wait()) {
73
0
    this->SetError(
74
0
      cmStrCat("Failed to wait on objdump process for:\n  ", file));
75
0
    return false;
76
0
  }
77
0
  if (process.GetStatus(0).ExitStatus != 0) {
78
0
    this->SetError(cmStrCat("Failed to run objdump on:\n  ", file));
79
0
    return false;
80
0
  }
81
82
0
  return true;
83
0
}