ホーム › System.Diagnostics.Debug › FindDebugInfoFile
FindDebugInfoFile
関数シンボルパスからデバッグ情報ファイルを検索する。
シグネチャ
// dbghelp.dll
#include <windows.h>
HANDLE FindDebugInfoFile(
LPCSTR FileName,
LPCSTR SymbolPath,
LPSTR DebugFilePath
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| FileName | LPCSTR | in | 検索対象の .dbg ファイルの名前。部分的なパスを使用できます。 |
| SymbolPath | LPCSTR | in | シンボルファイルが配置されているパス。セミコロンで区切って複数のパスを指定できます。シンボルパスを取得するには、 SymGetSearchPath 関数を使用します。 |
| DebugFilePath | LPSTR | out | .dbg ファイルの完全パスを受け取るバッファーへのポインター。このバッファーは少なくとも MAX_PATH+1 文字分必要です。 |
戻り値の型: HANDLE
公式ドキュメント
デバッグ (.dbg) ファイルを検索します。
戻り値
関数が成功した場合、戻り値は .dbg ファイルへのオープンされたハンドルです。
関数が失敗した場合、戻り値は NULL です。詳細なエラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
FindDebugInfoFile 関数は、.dbg ファイルを検索するために使用します。この関数は、1 回の関数呼び出しで複数の異なるディレクトリにわたって検索を実行できるように提供されています。SymbolPath パラメーターには、それぞれをセミコロン (;) で区切って複数のパスを含めることができます。複数のパスを指定した場合、関数は各ディレクトリ内でファイルを検索します。サブディレクトリは検索されません。ファイルが見つかると検索は停止します。したがって、SymbolPath のパスは正しい順序で指定してください。
この関数を含むすべての DbgHelp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性があります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// dbghelp.dll
#include <windows.h>
HANDLE FindDebugInfoFile(
LPCSTR FileName,
LPCSTR SymbolPath,
LPSTR DebugFilePath
);[DllImport("dbghelp.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindDebugInfoFile(
[MarshalAs(UnmanagedType.LPStr)] string FileName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string SymbolPath, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder DebugFilePath // LPSTR out
);<DllImport("dbghelp.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindDebugInfoFile(
<MarshalAs(UnmanagedType.LPStr)> FileName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> SymbolPath As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> DebugFilePath As System.Text.StringBuilder ' LPSTR out
) As IntPtr
End Function' FileName : LPCSTR
' SymbolPath : LPCSTR
' DebugFilePath : LPSTR out
Declare PtrSafe Function FindDebugInfoFile Lib "dbghelp" ( _
ByVal FileName As String, _
ByVal SymbolPath As String, _
ByVal DebugFilePath As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FindDebugInfoFile = ctypes.windll.dbghelp.FindDebugInfoFile
FindDebugInfoFile.restype = ctypes.c_void_p
FindDebugInfoFile.argtypes = [
wintypes.LPCSTR, # FileName : LPCSTR
wintypes.LPCSTR, # SymbolPath : LPCSTR
wintypes.LPSTR, # DebugFilePath : LPSTR out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('dbghelp.dll')
FindDebugInfoFile = Fiddle::Function.new(
lib['FindDebugInfoFile'],
[
Fiddle::TYPE_VOIDP, # FileName : LPCSTR
Fiddle::TYPE_VOIDP, # SymbolPath : LPCSTR
Fiddle::TYPE_VOIDP, # DebugFilePath : LPSTR out
],
Fiddle::TYPE_VOIDP)#[link(name = "dbghelp")]
extern "system" {
fn FindDebugInfoFile(
FileName: *const u8, // LPCSTR
SymbolPath: *const u8, // LPCSTR
DebugFilePath: *mut u8 // LPSTR out
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("dbghelp.dll", SetLastError = true)]
public static extern IntPtr FindDebugInfoFile([MarshalAs(UnmanagedType.LPStr)] string FileName, [MarshalAs(UnmanagedType.LPStr)] string SymbolPath, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder DebugFilePath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_FindDebugInfoFile' -Namespace Win32 -PassThru
# $api::FindDebugInfoFile(FileName, SymbolPath, DebugFilePath)#uselib "dbghelp.dll"
#func global FindDebugInfoFile "FindDebugInfoFile" sptr, sptr, sptr
; FindDebugInfoFile FileName, SymbolPath, varptr(DebugFilePath) ; 戻り値は stat
; FileName : LPCSTR -> "sptr"
; SymbolPath : LPCSTR -> "sptr"
; DebugFilePath : LPSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "dbghelp.dll" #cfunc global FindDebugInfoFile "FindDebugInfoFile" str, str, var ; res = FindDebugInfoFile(FileName, SymbolPath, DebugFilePath) ; FileName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; DebugFilePath : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "dbghelp.dll" #cfunc global FindDebugInfoFile "FindDebugInfoFile" str, str, sptr ; res = FindDebugInfoFile(FileName, SymbolPath, varptr(DebugFilePath)) ; FileName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; DebugFilePath : LPSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HANDLE FindDebugInfoFile(LPCSTR FileName, LPCSTR SymbolPath, LPSTR DebugFilePath) #uselib "dbghelp.dll" #cfunc global FindDebugInfoFile "FindDebugInfoFile" str, str, var ; res = FindDebugInfoFile(FileName, SymbolPath, DebugFilePath) ; FileName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; DebugFilePath : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HANDLE FindDebugInfoFile(LPCSTR FileName, LPCSTR SymbolPath, LPSTR DebugFilePath) #uselib "dbghelp.dll" #cfunc global FindDebugInfoFile "FindDebugInfoFile" str, str, intptr ; res = FindDebugInfoFile(FileName, SymbolPath, varptr(DebugFilePath)) ; FileName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; DebugFilePath : LPSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
procFindDebugInfoFile = dbghelp.NewProc("FindDebugInfoFile")
)
// FileName (LPCSTR), SymbolPath (LPCSTR), DebugFilePath (LPSTR out)
r1, _, err := procFindDebugInfoFile.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(FileName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(SymbolPath))),
uintptr(DebugFilePath),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction FindDebugInfoFile(
FileName: PAnsiChar; // LPCSTR
SymbolPath: PAnsiChar; // LPCSTR
DebugFilePath: PAnsiChar // LPSTR out
): THandle; stdcall;
external 'dbghelp.dll' name 'FindDebugInfoFile';result := DllCall("dbghelp\FindDebugInfoFile"
, "AStr", FileName ; LPCSTR
, "AStr", SymbolPath ; LPCSTR
, "Ptr", DebugFilePath ; LPSTR out
, "Ptr") ; return: HANDLE●FindDebugInfoFile(FileName, SymbolPath, DebugFilePath) = DLL("dbghelp.dll", "void* FindDebugInfoFile(char*, char*, char*)")
# 呼び出し: FindDebugInfoFile(FileName, SymbolPath, DebugFilePath)
# FileName : LPCSTR -> "char*"
# SymbolPath : LPCSTR -> "char*"
# DebugFilePath : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "dbghelp" fn FindDebugInfoFile(
FileName: [*c]const u8, // LPCSTR
SymbolPath: [*c]const u8, // LPCSTR
DebugFilePath: [*c]u8 // LPSTR out
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc FindDebugInfoFile(
FileName: cstring, # LPCSTR
SymbolPath: cstring, # LPCSTR
DebugFilePath: ptr char # LPSTR out
): pointer {.importc: "FindDebugInfoFile", stdcall, dynlib: "dbghelp.dll".}pragma(lib, "dbghelp");
extern(Windows)
void* FindDebugInfoFile(
const(char)* FileName, // LPCSTR
const(char)* SymbolPath, // LPCSTR
char* DebugFilePath // LPSTR out
);ccall((:FindDebugInfoFile, "dbghelp.dll"), stdcall, Ptr{Cvoid},
(Cstring, Cstring, Ptr{UInt8}),
FileName, SymbolPath, DebugFilePath)
# FileName : LPCSTR -> Cstring
# SymbolPath : LPCSTR -> Cstring
# DebugFilePath : LPSTR out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* FindDebugInfoFile(
const char* FileName,
const char* SymbolPath,
char* DebugFilePath);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.FindDebugInfoFile(FileName, SymbolPath, DebugFilePath)
-- FileName : LPCSTR
-- SymbolPath : LPCSTR
-- DebugFilePath : LPSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const FindDebugInfoFile = lib.func('__stdcall', 'FindDebugInfoFile', 'void *', ['str', 'str', 'char *']);
// FindDebugInfoFile(FileName, SymbolPath, DebugFilePath)
// FileName : LPCSTR -> 'str'
// SymbolPath : LPCSTR -> 'str'
// DebugFilePath : LPSTR out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("dbghelp.dll", {
FindDebugInfoFile: { parameters: ["buffer", "buffer", "buffer"], result: "pointer" },
});
// lib.symbols.FindDebugInfoFile(FileName, SymbolPath, DebugFilePath)
// FileName : LPCSTR -> "buffer"
// SymbolPath : LPCSTR -> "buffer"
// DebugFilePath : LPSTR out -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* FindDebugInfoFile(
const char* FileName,
const char* SymbolPath,
char* DebugFilePath);
C, "dbghelp.dll");
// $ffi->FindDebugInfoFile(FileName, SymbolPath, DebugFilePath);
// FileName : LPCSTR
// SymbolPath : LPCSTR
// DebugFilePath : LPSTR out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Dbghelp extends StdCallLibrary {
Dbghelp INSTANCE = Native.load("dbghelp", Dbghelp.class);
Pointer FindDebugInfoFile(
String FileName, // LPCSTR
String SymbolPath, // LPCSTR
byte[] DebugFilePath // LPSTR out
);
}@[Link("dbghelp")]
lib Libdbghelp
fun FindDebugInfoFile = FindDebugInfoFile(
FileName : UInt8*, # LPCSTR
SymbolPath : UInt8*, # LPCSTR
DebugFilePath : UInt8* # LPSTR out
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef FindDebugInfoFileNative = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>);
typedef FindDebugInfoFileDart = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>);
final FindDebugInfoFile = DynamicLibrary.open('dbghelp.dll')
.lookupFunction<FindDebugInfoFileNative, FindDebugInfoFileDart>('FindDebugInfoFile');
// FileName : LPCSTR -> Pointer<Utf8>
// SymbolPath : LPCSTR -> Pointer<Utf8>
// DebugFilePath : LPSTR out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function FindDebugInfoFile(
FileName: PAnsiChar; // LPCSTR
SymbolPath: PAnsiChar; // LPCSTR
DebugFilePath: PAnsiChar // LPSTR out
): THandle; stdcall;
external 'dbghelp.dll' name 'FindDebugInfoFile';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "FindDebugInfoFile"
c_FindDebugInfoFile :: CString -> CString -> CString -> IO (Ptr ())
-- FileName : LPCSTR -> CString
-- SymbolPath : LPCSTR -> CString
-- DebugFilePath : LPSTR out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let finddebuginfofile =
foreign "FindDebugInfoFile"
(string @-> string @-> string @-> returning (ptr void))
(* FileName : LPCSTR -> string *)
(* SymbolPath : LPCSTR -> string *)
(* DebugFilePath : LPSTR out -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)
(cffi:defcfun ("FindDebugInfoFile" find-debug-info-file :convention :stdcall) :pointer
(file-name :string) ; LPCSTR
(symbol-path :string) ; LPCSTR
(debug-file-path :pointer)) ; LPSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $FindDebugInfoFile = Win32::API::More->new('dbghelp',
'HANDLE FindDebugInfoFile(LPCSTR FileName, LPCSTR SymbolPath, LPSTR DebugFilePath)');
# my $ret = $FindDebugInfoFile->Call($FileName, $SymbolPath, $DebugFilePath);
# FileName : LPCSTR -> LPCSTR
# SymbolPath : LPCSTR -> LPCSTR
# DebugFilePath : LPSTR out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f FindDebugInfoFileExW — コールバック付きでデバッグ情報ファイルを検索する拡張版である。
公式の関連項目
- f SymGetSearchPathW — シンボル検索パスを取得する(Unicode版)。