Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.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 "cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.h"
5
6
#include <istream> // IWYU pragma: keep
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
cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool::
18
  cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool(
19
    cmRuntimeDependencyArchive* archive)
20
0
  : cmBinUtilsWindowsPEGetRuntimeDependenciesTool(archive)
21
0
{
22
0
}
23
24
bool cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool::GetFileInfo(
25
  std::string const& file, std::vector<std::string>& needed)
26
0
{
27
0
  cmUVProcessChainBuilder builder;
28
0
  builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT);
29
30
0
  std::vector<std::string> command;
31
0
  if (!this->Archive->GetGetRuntimeDependenciesCommand("objdump", command)) {
32
0
    this->SetError("Could not find objdump");
33
0
    return false;
34
0
  }
35
0
  command.emplace_back("-p");
36
0
  command.push_back(file);
37
0
  builder.AddCommand(command);
38
39
0
  auto process = builder.Start();
40
0
  if (!process.Valid() || process.GetStatus(0).SpawnResult != 0) {
41
0
    this->SetError(cmStrCat("Failed to start objdump process for:\n  ", file));
42
0
    return false;
43
0
  }
44
45
0
  std::string line;
46
0
  static cmsys::RegularExpression const regex(
47
0
    "^[\t ]*DLL Name: ([^\n]*\\.[Dd][Ll][Ll])$");
48
0
  cmUVIStream output(process.OutputStream());
49
0
  while (cmSystemTools::GetLineFromStream(output, line)) {
50
0
    cmsys::RegularExpressionMatch match;
51
0
    if (regex.find(line.c_str(), match)) {
52
0
      needed.push_back(match.match(1));
53
0
    }
54
0
  }
55
56
0
  if (!process.Wait()) {
57
0
    this->SetError(
58
0
      cmStrCat("Failed to wait on objdump process for:\n  ", file));
59
0
    return false;
60
0
  }
61
0
  if (process.GetStatus(0).ExitStatus != 0) {
62
0
    this->SetError(cmStrCat("Failed to run objdump on:\n  ", file));
63
0
    return false;
64
0
  }
65
66
0
  return true;
67
0
}