Coverage Report

Created: 2026-03-12 06:35

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 <sstream>
7
#include <vector>
8
9
#include <cmsys/RegularExpression.hxx>
10
11
#include "cmRuntimeDependencyArchive.h"
12
#include "cmSystemTools.h"
13
#include "cmUVProcessChain.h"
14
#include "cmUVStream.h"
15
16
cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool::
17
  cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool(
18
    cmRuntimeDependencyArchive* archive)
19
0
  : cmBinUtilsWindowsPEGetRuntimeDependenciesTool(archive)
20
0
{
21
0
}
22
23
bool cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool::GetFileInfo(
24
  std::string const& file, std::vector<std::string>& needed)
25
0
{
26
0
  cmUVProcessChainBuilder builder;
27
0
  builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT);
28
29
0
  std::vector<std::string> command;
30
0
  if (!this->Archive->GetGetRuntimeDependenciesCommand("objdump", command)) {
31
0
    this->SetError("Could not find objdump");
32
0
    return false;
33
0
  }
34
0
  command.emplace_back("-p");
35
0
  command.push_back(file);
36
0
  builder.AddCommand(command);
37
38
0
  auto process = builder.Start();
39
0
  if (!process.Valid() || process.GetStatus(0).SpawnResult != 0) {
40
0
    std::ostringstream e;
41
0
    e << "Failed to start objdump process for:\n  " << file;
42
0
    this->SetError(e.str());
43
0
    return false;
44
0
  }
45
46
0
  std::string line;
47
0
  static cmsys::RegularExpression const regex(
48
0
    "^[\t ]*DLL Name: ([^\n]*\\.[Dd][Ll][Ll])$");
49
0
  cmUVIStream output(process.OutputStream());
50
0
  while (cmSystemTools::GetLineFromStream(output, line)) {
51
0
    cmsys::RegularExpressionMatch match;
52
0
    if (regex.find(line.c_str(), match)) {
53
0
      needed.push_back(match.match(1));
54
0
    }
55
0
  }
56
57
0
  if (!process.Wait()) {
58
0
    std::ostringstream e;
59
0
    e << "Failed to wait on objdump process for:\n  " << file;
60
0
    this->SetError(e.str());
61
0
    return false;
62
0
  }
63
0
  if (process.GetStatus(0).ExitStatus != 0) {
64
0
    std::ostringstream e;
65
0
    e << "Failed to run objdump on:\n  " << file;
66
0
    this->SetError(e.str());
67
0
    return false;
68
0
  }
69
70
0
  return true;
71
0
}