Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › UpdateDebugInfoFileEx

UpdateDebugInfoFileEx

関数
旧チェックサム検証付きでデバッグ情報ファイルを更新する拡張版である。
DLLimagehlp.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// imagehlp.dll
#include <windows.h>

BOOL UpdateDebugInfoFileEx(
    LPCSTR ImageFileName,
    LPCSTR SymbolPath,
    LPSTR DebugFilePath,
    IMAGE_NT_HEADERS32* NtHeaders,
    DWORD OldCheckSum
);

パラメーター

名前方向説明
ImageFileNameLPCSTRinシンボルファイルに対して内容が古くなっているイメージの名前。
SymbolPathLPCSTRinシンボルファイルを検索するパス。
DebugFilePathLPSTRout更新されたシンボルファイルの名前を受け取るバッファーへのポインター。
NtHeadersIMAGE_NT_HEADERS32*in新しいヘッダー情報を指定する IMAGE_NT_HEADERS 構造体へのポインター。
OldCheckSumDWORDin元のチェックサム値。この値がマップされたイメージに存在するチェックサムと一致しない場合、シンボルファイルのフラグに IMAGE_SEPARATE_DEBUG_MISMATCH が設定され、最後のエラー値は ERROR_INVALID_DATA に設定されます。

戻り値の型: BOOL

公式ドキュメント

指定された拡張情報を使用して、シンボルファイル内の対応するフィールドを更新します。

戻り値

関数が成功した場合、戻り値は TRUE です。

関数が失敗した場合、戻り値は FALSE です。

解説(Remarks)

UpdateDebugInfoFileEx 関数は、 IMAGE_NT_HEADERS 構造体に格納された情報を取得し、シンボルファイル内の対応するフィールドを更新します。イメージファイルが変更されるたびに、数値を同期させるためにこの関数を呼び出す必要があります。具体的には、イメージのチェックサムが変更されるたびに、それに合わせてシンボルファイルを更新する必要があります。

この関数を含むすべての ImageHlp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性があります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期させる必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// imagehlp.dll
#include <windows.h>

BOOL UpdateDebugInfoFileEx(
    LPCSTR ImageFileName,
    LPCSTR SymbolPath,
    LPSTR DebugFilePath,
    IMAGE_NT_HEADERS32* NtHeaders,
    DWORD OldCheckSum
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll", ExactSpelling = true)]
static extern bool UpdateDebugInfoFileEx(
    [MarshalAs(UnmanagedType.LPStr)] string ImageFileName,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string SymbolPath,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder DebugFilePath,   // LPSTR out
    IntPtr NtHeaders,   // IMAGE_NT_HEADERS32*
    uint OldCheckSum   // DWORD
);
<DllImport("imagehlp.dll", ExactSpelling:=True)>
Public Shared Function UpdateDebugInfoFileEx(
    <MarshalAs(UnmanagedType.LPStr)> ImageFileName As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> SymbolPath As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> DebugFilePath As System.Text.StringBuilder,   ' LPSTR out
    NtHeaders As IntPtr,   ' IMAGE_NT_HEADERS32*
    OldCheckSum As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' ImageFileName : LPCSTR
' SymbolPath : LPCSTR
' DebugFilePath : LPSTR out
' NtHeaders : IMAGE_NT_HEADERS32*
' OldCheckSum : DWORD
Declare PtrSafe Function UpdateDebugInfoFileEx Lib "imagehlp" ( _
    ByVal ImageFileName As String, _
    ByVal SymbolPath As String, _
    ByVal DebugFilePath As String, _
    ByVal NtHeaders As LongPtr, _
    ByVal OldCheckSum As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

UpdateDebugInfoFileEx = ctypes.windll.imagehlp.UpdateDebugInfoFileEx
UpdateDebugInfoFileEx.restype = wintypes.BOOL
UpdateDebugInfoFileEx.argtypes = [
    wintypes.LPCSTR,  # ImageFileName : LPCSTR
    wintypes.LPCSTR,  # SymbolPath : LPCSTR
    wintypes.LPSTR,  # DebugFilePath : LPSTR out
    ctypes.c_void_p,  # NtHeaders : IMAGE_NT_HEADERS32*
    wintypes.DWORD,  # OldCheckSum : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('imagehlp.dll')
UpdateDebugInfoFileEx = Fiddle::Function.new(
  lib['UpdateDebugInfoFileEx'],
  [
    Fiddle::TYPE_VOIDP,  # ImageFileName : LPCSTR
    Fiddle::TYPE_VOIDP,  # SymbolPath : LPCSTR
    Fiddle::TYPE_VOIDP,  # DebugFilePath : LPSTR out
    Fiddle::TYPE_VOIDP,  # NtHeaders : IMAGE_NT_HEADERS32*
    -Fiddle::TYPE_INT,  # OldCheckSum : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "imagehlp")]
extern "system" {
    fn UpdateDebugInfoFileEx(
        ImageFileName: *const u8,  // LPCSTR
        SymbolPath: *const u8,  // LPCSTR
        DebugFilePath: *mut u8,  // LPSTR out
        NtHeaders: *mut IMAGE_NT_HEADERS32,  // IMAGE_NT_HEADERS32*
        OldCheckSum: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll")]
public static extern bool UpdateDebugInfoFileEx([MarshalAs(UnmanagedType.LPStr)] string ImageFileName, [MarshalAs(UnmanagedType.LPStr)] string SymbolPath, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder DebugFilePath, IntPtr NtHeaders, uint OldCheckSum);
"@
$api = Add-Type -MemberDefinition $sig -Name 'imagehlp_UpdateDebugInfoFileEx' -Namespace Win32 -PassThru
# $api::UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum)
#uselib "imagehlp.dll"
#func global UpdateDebugInfoFileEx "UpdateDebugInfoFileEx" sptr, sptr, sptr, sptr, sptr
; UpdateDebugInfoFileEx ImageFileName, SymbolPath, varptr(DebugFilePath), varptr(NtHeaders), OldCheckSum   ; 戻り値は stat
; ImageFileName : LPCSTR -> "sptr"
; SymbolPath : LPCSTR -> "sptr"
; DebugFilePath : LPSTR out -> "sptr"
; NtHeaders : IMAGE_NT_HEADERS32* -> "sptr"
; OldCheckSum : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "imagehlp.dll"
#cfunc global UpdateDebugInfoFileEx "UpdateDebugInfoFileEx" str, str, var, var, int
; res = UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum)
; ImageFileName : LPCSTR -> "str"
; SymbolPath : LPCSTR -> "str"
; DebugFilePath : LPSTR out -> "var"
; NtHeaders : IMAGE_NT_HEADERS32* -> "var"
; OldCheckSum : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL UpdateDebugInfoFileEx(LPCSTR ImageFileName, LPCSTR SymbolPath, LPSTR DebugFilePath, IMAGE_NT_HEADERS32* NtHeaders, DWORD OldCheckSum)
#uselib "imagehlp.dll"
#cfunc global UpdateDebugInfoFileEx "UpdateDebugInfoFileEx" str, str, var, var, int
; res = UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum)
; ImageFileName : LPCSTR -> "str"
; SymbolPath : LPCSTR -> "str"
; DebugFilePath : LPSTR out -> "var"
; NtHeaders : IMAGE_NT_HEADERS32* -> "var"
; OldCheckSum : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	imagehlp = windows.NewLazySystemDLL("imagehlp.dll")
	procUpdateDebugInfoFileEx = imagehlp.NewProc("UpdateDebugInfoFileEx")
)

// ImageFileName (LPCSTR), SymbolPath (LPCSTR), DebugFilePath (LPSTR out), NtHeaders (IMAGE_NT_HEADERS32*), OldCheckSum (DWORD)
r1, _, err := procUpdateDebugInfoFileEx.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(ImageFileName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SymbolPath))),
	uintptr(DebugFilePath),
	uintptr(NtHeaders),
	uintptr(OldCheckSum),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function UpdateDebugInfoFileEx(
  ImageFileName: PAnsiChar;   // LPCSTR
  SymbolPath: PAnsiChar;   // LPCSTR
  DebugFilePath: PAnsiChar;   // LPSTR out
  NtHeaders: Pointer;   // IMAGE_NT_HEADERS32*
  OldCheckSum: DWORD   // DWORD
): BOOL; stdcall;
  external 'imagehlp.dll' name 'UpdateDebugInfoFileEx';
result := DllCall("imagehlp\UpdateDebugInfoFileEx"
    , "AStr", ImageFileName   ; LPCSTR
    , "AStr", SymbolPath   ; LPCSTR
    , "Ptr", DebugFilePath   ; LPSTR out
    , "Ptr", NtHeaders   ; IMAGE_NT_HEADERS32*
    , "UInt", OldCheckSum   ; DWORD
    , "Int")   ; return: BOOL
●UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum) = DLL("imagehlp.dll", "bool UpdateDebugInfoFileEx(char*, char*, char*, void*, dword)")
# 呼び出し: UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum)
# ImageFileName : LPCSTR -> "char*"
# SymbolPath : LPCSTR -> "char*"
# DebugFilePath : LPSTR out -> "char*"
# NtHeaders : IMAGE_NT_HEADERS32* -> "void*"
# OldCheckSum : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "imagehlp" fn UpdateDebugInfoFileEx(
    ImageFileName: [*c]const u8, // LPCSTR
    SymbolPath: [*c]const u8, // LPCSTR
    DebugFilePath: [*c]u8, // LPSTR out
    NtHeaders: [*c]IMAGE_NT_HEADERS32, // IMAGE_NT_HEADERS32*
    OldCheckSum: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc UpdateDebugInfoFileEx(
    ImageFileName: cstring,  # LPCSTR
    SymbolPath: cstring,  # LPCSTR
    DebugFilePath: ptr char,  # LPSTR out
    NtHeaders: ptr IMAGE_NT_HEADERS32,  # IMAGE_NT_HEADERS32*
    OldCheckSum: uint32  # DWORD
): int32 {.importc: "UpdateDebugInfoFileEx", stdcall, dynlib: "imagehlp.dll".}
pragma(lib, "imagehlp");
extern(Windows)
int UpdateDebugInfoFileEx(
    const(char)* ImageFileName,   // LPCSTR
    const(char)* SymbolPath,   // LPCSTR
    char* DebugFilePath,   // LPSTR out
    IMAGE_NT_HEADERS32* NtHeaders,   // IMAGE_NT_HEADERS32*
    uint OldCheckSum   // DWORD
);
ccall((:UpdateDebugInfoFileEx, "imagehlp.dll"), stdcall, Int32,
      (Cstring, Cstring, Ptr{UInt8}, Ptr{IMAGE_NT_HEADERS32}, UInt32),
      ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum)
# ImageFileName : LPCSTR -> Cstring
# SymbolPath : LPCSTR -> Cstring
# DebugFilePath : LPSTR out -> Ptr{UInt8}
# NtHeaders : IMAGE_NT_HEADERS32* -> Ptr{IMAGE_NT_HEADERS32}
# OldCheckSum : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t UpdateDebugInfoFileEx(
    const char* ImageFileName,
    const char* SymbolPath,
    char* DebugFilePath,
    void* NtHeaders,
    uint32_t OldCheckSum);
]]
local imagehlp = ffi.load("imagehlp")
-- imagehlp.UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum)
-- ImageFileName : LPCSTR
-- SymbolPath : LPCSTR
-- DebugFilePath : LPSTR out
-- NtHeaders : IMAGE_NT_HEADERS32*
-- OldCheckSum : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('imagehlp.dll');
const UpdateDebugInfoFileEx = lib.func('__stdcall', 'UpdateDebugInfoFileEx', 'int32_t', ['str', 'str', 'char *', 'void *', 'uint32_t']);
// UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum)
// ImageFileName : LPCSTR -> 'str'
// SymbolPath : LPCSTR -> 'str'
// DebugFilePath : LPSTR out -> 'char *'
// NtHeaders : IMAGE_NT_HEADERS32* -> 'void *'
// OldCheckSum : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("imagehlp.dll", {
  UpdateDebugInfoFileEx: { parameters: ["buffer", "buffer", "buffer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum)
// ImageFileName : LPCSTR -> "buffer"
// SymbolPath : LPCSTR -> "buffer"
// DebugFilePath : LPSTR out -> "buffer"
// NtHeaders : IMAGE_NT_HEADERS32* -> "pointer"
// OldCheckSum : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t UpdateDebugInfoFileEx(
    const char* ImageFileName,
    const char* SymbolPath,
    char* DebugFilePath,
    void* NtHeaders,
    uint32_t OldCheckSum);
C, "imagehlp.dll");
// $ffi->UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath, NtHeaders, OldCheckSum);
// ImageFileName : LPCSTR
// SymbolPath : LPCSTR
// DebugFilePath : LPSTR out
// NtHeaders : IMAGE_NT_HEADERS32*
// OldCheckSum : DWORD
// 構造体/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 Imagehlp extends StdCallLibrary {
    Imagehlp INSTANCE = Native.load("imagehlp", Imagehlp.class);
    boolean UpdateDebugInfoFileEx(
        String ImageFileName,   // LPCSTR
        String SymbolPath,   // LPCSTR
        byte[] DebugFilePath,   // LPSTR out
        Pointer NtHeaders,   // IMAGE_NT_HEADERS32*
        int OldCheckSum   // DWORD
    );
}
@[Link("imagehlp")]
lib Libimagehlp
  fun UpdateDebugInfoFileEx = UpdateDebugInfoFileEx(
    ImageFileName : UInt8*,   # LPCSTR
    SymbolPath : UInt8*,   # LPCSTR
    DebugFilePath : UInt8*,   # LPSTR out
    NtHeaders : IMAGE_NT_HEADERS32*,   # IMAGE_NT_HEADERS32*
    OldCheckSum : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef UpdateDebugInfoFileExNative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>, Uint32);
typedef UpdateDebugInfoFileExDart = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>, int);
final UpdateDebugInfoFileEx = DynamicLibrary.open('imagehlp.dll')
    .lookupFunction<UpdateDebugInfoFileExNative, UpdateDebugInfoFileExDart>('UpdateDebugInfoFileEx');
// ImageFileName : LPCSTR -> Pointer<Utf8>
// SymbolPath : LPCSTR -> Pointer<Utf8>
// DebugFilePath : LPSTR out -> Pointer<Utf8>
// NtHeaders : IMAGE_NT_HEADERS32* -> Pointer<Void>
// OldCheckSum : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function UpdateDebugInfoFileEx(
  ImageFileName: PAnsiChar;   // LPCSTR
  SymbolPath: PAnsiChar;   // LPCSTR
  DebugFilePath: PAnsiChar;   // LPSTR out
  NtHeaders: Pointer;   // IMAGE_NT_HEADERS32*
  OldCheckSum: DWORD   // DWORD
): BOOL; stdcall;
  external 'imagehlp.dll' name 'UpdateDebugInfoFileEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "UpdateDebugInfoFileEx"
  c_UpdateDebugInfoFileEx :: CString -> CString -> CString -> Ptr () -> Word32 -> IO CInt
-- ImageFileName : LPCSTR -> CString
-- SymbolPath : LPCSTR -> CString
-- DebugFilePath : LPSTR out -> CString
-- NtHeaders : IMAGE_NT_HEADERS32* -> Ptr ()
-- OldCheckSum : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let updatedebuginfofileex =
  foreign "UpdateDebugInfoFileEx"
    (string @-> string @-> string @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* ImageFileName : LPCSTR -> string *)
(* SymbolPath : LPCSTR -> string *)
(* DebugFilePath : LPSTR out -> string *)
(* NtHeaders : IMAGE_NT_HEADERS32* -> (ptr void) *)
(* OldCheckSum : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library imagehlp (t "imagehlp.dll"))
(cffi:use-foreign-library imagehlp)

(cffi:defcfun ("UpdateDebugInfoFileEx" update-debug-info-file-ex :convention :stdcall) :int32
  (image-file-name :string)   ; LPCSTR
  (symbol-path :string)   ; LPCSTR
  (debug-file-path :pointer)   ; LPSTR out
  (nt-headers :pointer)   ; IMAGE_NT_HEADERS32*
  (old-check-sum :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $UpdateDebugInfoFileEx = Win32::API::More->new('imagehlp',
    'BOOL UpdateDebugInfoFileEx(LPCSTR ImageFileName, LPCSTR SymbolPath, LPSTR DebugFilePath, LPVOID NtHeaders, DWORD OldCheckSum)');
# my $ret = $UpdateDebugInfoFileEx->Call($ImageFileName, $SymbolPath, $DebugFilePath, $NtHeaders, $OldCheckSum);
# ImageFileName : LPCSTR -> LPCSTR
# SymbolPath : LPCSTR -> LPCSTR
# DebugFilePath : LPSTR out -> LPSTR
# NtHeaders : IMAGE_NT_HEADERS32* -> LPVOID
# OldCheckSum : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
使用する型