VS 2005使用map文件查找程序崩溃原因(转载,很好)

一般程序崩溃可以通过debug,找到程序在那一行代码崩溃了,最近编一个多线程的程序,都不知道在那发生错误,多线程并发,又不好单行调试,终于找到一个比较好的方法来找原因,通过生成map文件,由于2005取消map文件生成行号信息(vc6.0下是可以生成行号信息的,不知道microsoft怎么想的,在2005上取消了),只能定位在那个函数发生崩溃。这里可以通过生成cod文件,即机器码这一文件,具体定位在那一行崩溃。

首先配置vc2005生成map文件和cod文件:
(1).map文件:property->Configuration Properties->Linker->Debugging 中的Generate Map File选择Yes(/MAP);

(2).cod文件:property->Configuration Properties->C/C++->output Files中Assembler OutPut中选择Assembly,Maching Code and Source(/FAcs),生成机器,源代码。

上面所说的 property 是“项目”菜单下的 property,而非“工具”菜单下的 property。(转者注)

简单例子:

#include "stdafx.h"

void errorFun(int * p)
{
*p=1;
}

int _tmain(int argc, _TCHAR* argv[])
{
int * p=NULL;
errorFun(p);
return 0;
}

在errorFun中函数中,*p=1这一行出错,由于p没有申请空间,运行时出错,弹出
Unhandled exception at 0x004113b1 in testError.exe: 0xC0000005: Access violation writing location 0x00000000.
在0x004113b1程序发生崩溃。

[b]具体步骤:[/b]
(1)debug文件下打开map文件,定位崩溃函数.

map文件开头是一些链接信息,然后我们要找函数和实始地址信息。地址是函始的开始地址

Address       Publics by Value       Rva+Base    Lib:Object

0000:00000000    ___safe_se_handler_count   00000000    <absolute>
0000:00000000    ___safe_se_handler_table   00000000    <absolute>
0000:00000000    ___ImageBase         00400000    <linker-defined>
0001:00000000    __enc$textbss$begin      00401000     <linker-defined>
0001:00010000    __enc$textbss$end       00411000     <linker-defined>
0002:00000390    [color=red]?errorFun@@YAXPAH@Z    00411390 f    testError.obj[/color]
0002:000003d0    _wmain            [color=red]004113d0 f[/color]    testError.obj
0002:00000430    __RTC_InitBase        00411430 f   MSVCRTD:init.obj
0002:00000470    __RTC_Shutdown        00411470 f   MSVCRTD:init.obj
0002:00000490    __RTC_CheckEsp        00411490 f   MSVCRTD:stack.obj
0002:000004c0    @_RTC_CheckStackVars@8    004114c0 f   MSVCRTD:stack.obj
0002:00000540    @_RTC_AllocaHelper@12     00411540 f    MSVCRTD:stack.obj

....

程序崩溃地址0x004113b1,我们找到第一个比这个地址大的004113d0,前一个是00411390,地址是函数的开始地址,所以发生的崩溃的的函数是errorFun,这个函数的初始地址00411390.

(2)找出具体崩溃行号.

由(2)可知,发生错误函数是errorFun,在testError.obj,打开testError.cod文件,找到errorFun函数生成的机器码.

?errorFun@@YAXPAH@Z PROC ; errorFun, COMDAT

; 7 : {

00000 55 push ebp
00001 8b ec mov ebp, esp
00003 81 ec c0 00 00
00 sub esp, 192 ; 000000c0H
00009 53 push ebx
0000a 56 push esi
0000b 57 push edi
0000c 8d bd 40 ff ff
ff lea edi, DWORD PTR [ebp-192]
00012 b9 30 00 00 00 mov ecx, 48 ; 00000030H
00017 b8 cc cc cc cc mov eax, -858993460 ; ccccccccH
0001c f3 ab rep stosd

; 8 : *p=1;

0001e 8b 45 08 mov eax, DWORD PTR _p$[ebp]
[color=red]00021[/color] c7 00 01 00 00
00 mov DWORD PTR [eax], 1

; 9 : }

00027 5f pop edi
00028 5e pop esi
00029 5b pop ebx
0002a 8b e5 mov esp, ebp
0002c 5d pop ebp
0002d c3 ret 0
(说明: 7,8,9是表示在源代码的行号。
00000 55 push ebp,000000是相对偏移地地,55是机器码号,push ebp,000000是汇编码。)

通过(2)我们计算相对偏移地址,即崩溃地址-函数起始地址,0x004113b1-0x00411390=0x21(16进制的计数)。找到0x21这一行对应的机器码是 00021 c7 00 01 00 00,向上看它是由第8行*p=1;生成的汇编码,由此可见是这一行程序发生崩溃。


结束语:当然这只是一个简单的例子,实际上一运行便知道是这一行出错,但是对于一个比较大的工程,特别是在多线程并发情况下,要找出那一行出错比较困难,便可以使用map和cod文件找到程序崩溃原因。
VS+MAP文件(崩溃地址定位崩溃行) 根据win32程序崩溃地址定位崩溃行 立即下载

相关推荐

使用map文件查找程序崩溃原因

一般程序崩溃可以通过debug,找到程序在那一行代码崩溃了,最近编一个多线程的程序,都不知道在那发生错误,多线程并发,又不好单行调试,终于找到一个比较好的方法来找原因,通过生成map文件,由于2005取消map文件生成行号信息(vc6.0下是可以生成行号信息的,不知道microsoft怎么想的,在2005上取消了),只能定位在那个函数发生崩溃。这里可以通过生成cod文件,即机器码这一文件,具体定位在那一行崩溃。

windows系统利用vs 分析DMP文件、pdb文件定位异常崩溃

exe文件、dmp文件和pdb文件必须保持一致!exe文件和pdb文件同时生成,dmp文件是由当前exe生成的。 设置生成 pdb 选择 项目 -> 工程名+属性,如下图所示。 之后选择 配置属性 -> 连接器 -> 调试,如下图所示。 上图中,“生成调试信息”为pdb文件生成与否的使能开关,“生成程序数据库文件”为该pdb文件的名字,默认即可。 DUMP文件 生成dump文件的办法 1.手动设置生成。在代码调试过程中,知道会出现bug的情况下,手动点击工具栏的调试..

baidu_16370559的博客 1万+

VS2008+mapX地图检索

在vs2008下建立mapX的开发环境(如何运用mapX控件),在这种环境下开发GIS简单快捷

Visual Studio环境下生成dump文件及利用dump文件定位程序出错位置

今天在网上学习了关于dump文件

wangzhen_cv的专栏 7875

【遥感数字图像处理(朱文泉)】第四章 变换域处理方法

变换域的处理方法

甜子yu的博客 4311

Anylogic试用版密匙

#$%99dTMbLIj+hm/c9fn0suWlfQjdK9FzRH8oSbR Rbm3FEeONkF5mDLKHxhscEDBANDg4BSU2Oi6hErk TH/KzwiCtsM0jfD50uRsj60+gi9ifTlduwcpSr6a GtVSilXwF997xTVAoMLddqOzGQAbnSjBiJOBdm1Z 0QwwIEJynvYgckLfoEADzncIgNnJjYshWcmGh3s9 gTgyuQPlRBeTXfb+ZJPI1JGi4sAUljwdB53Df+AX SEf5FaIbih

qq_43939616的博客 8267

如何定位错误,上传了mapping为什么还有Unknown Source及混淆后 bug如何显示行号

经常有人发邮件问我们一些很奇怪的问题,还会附上一段堆栈代码: 为什么友盟统计到的错误堆栈都变成 a.b.c 这样的不可读字符了? 为什么上传了 mapping文件之后还会出现(Unknown Source)? 11-11 09:36:42.262: E/AndroidRuntime(2065): Caused by: java.lang.ArithmeticExceptio

rrkdddd33的博客 1362

光耦CTR参数实战:如何避免误触发与功耗陷阱(附计算公式)

本文深入解析光耦CTR参数在电路设计中的关键作用,探讨如何平衡误触发风险与功耗表现。通过TLP521、PC817等常见型号的实测数据对比,提供不同工作状态下的选型策略和计算公式,帮助工程师优化设计,提升系统稳定性和能效。

2a4s6d8f0g的博客 323

map崩溃

当我们不清理map内存时,多次调用clear都没有问题,但是当我们释放内存了,再调用clear就会崩溃

weixin_45699553的博客 901

避坑指南:ANSYS流固耦合计算中System Coupling数据传递设置与常见报错解决

本文深入解析ANSYS Workbench中System Coupling模块在双向流固耦合(FSI)计算中的应用,详细讲解数据传递机制、典型报错解决方案及高阶调试技巧。通过实际案例展示如何优化耦合步长、处理大变形问题,并提升并行计算效率,帮助工程师有效规避常见技术陷阱。

weixin_29213525的博客 727

ardupilot SBUS输入捕获

本节主要记录ardupilot 的sbus 输入捕获功能。ardupilot 默认支持多种无线协议控制输入设备,比如常用的PPM,SBUS,IBUS,DSM,SUMD,SRXL等协议,本节主要讲解ardupilot 如何通过定时器的pwm输入捕获来获取sbus数据。

陌城烟雨 270

VS2005(vs2008,vs2010)使用map文件查找程序崩溃原因

VS2005(vs2008,vs2010)使用map文件查找程序崩溃原因(转载) 2011-07-18 14:04    一般程序崩溃可以通过debug,找到程序在那一行代码崩溃了,最近编一个多线程的程序,都不知道在那发生错误,多线程并发,又不好单行调试,终于找到一 个比较好的方法来找原因,通过生成map文件,由于2005取消map文件生成行号信息(vc

2165

【Docker】完美解决拉取镜像超时报错:ERROR: Get https://registry-1.docker.io/v2/

因为我们下载的镜像是外网的镜像资源,所以下载的速度会非常的慢,甚至大概率下载时会报错,所以需要我们配置一个国内的服务器镜像地址,国内服务器镜像地址有很多,这里咱们就说一下阿里镜像加速器的配置方法。

liu_chen_yang的博客 12万+

VS2005(vs2008,vs2010 VS2012)使用map文件查找程序崩溃原因

转载http://blog.youkuaiyun.com/luxiaoyu_sdc/article/details/6458872 一般程序崩溃可以通过debug,找到程序在那一行代码崩溃了,最近编一个多线程的程序,都不知道在那发生错误,多线程并发,又不好单行调试,终于找到一个比较好的方法来找原因,通过生成map文件,由于2005取消map文件生成行号信息(vc6.0下是可以生成行号...

weixin_30633507的博客 80

996引擎 - 【任务系统】和【cfg_newtask.xls】

996这个任务系统仅用于控制主界面左上角的【任务列表】,不包含具体任务的业务逻辑。任务列表有多个任务时支持上下滑动,可以调用接口将指定任务【置顶】任务列表中,每个任务一行,分标题和(当前状态对应的)内容两部分,点击能触发事件具体的任务系统业务逻辑,需要自己写代码实现。(配合996提供的任务接口和触发,实现更新任务列表)

灵台方寸山斜月三星洞 1429

从Safety Manual到系统安全概念

本文系统阐述了构建功能安全"证据链"的工程化方法论,核心要点包括:1)建立"风险→对策→验证→证据"闭环链条;2)SafetyManual和FMEDA作为关键证据支撑点,前者界定系统安全边界,后者量化诊断覆盖率;3)通过四步法继承芯片安全机制并扩展至系统级;4)形成"设计-分析-验证"三维闭环体系,包括安全目标、技术实现和验证矩阵;5)强调证据链闭环对安全认证和OEM认可的重要性。该方法论实现了从理论要求到工程实践的完整转化,确保安全设计可验证、可

VehSwHwDeveloper的博客 721

定位release版本程序的错误

程序Crash调试方式--MAP文件 vs2010利用map,cod文件定位崩溃代码行 调试Release发布版程序的Crash错误 VS2005(vs2008,vs2010)使用map文件查找程序崩溃原因 转载于:https://www.cnblogs.com/TenosDoIt/articles/3583339.html...

weixin_34032621的博客 140

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

如何诊断Windows CE的应用程序崩溃(转载)

无论你是一个单纯的电脑用户还是一名高级软件工程师,都一定对程序崩溃不陌生。做为一名Windows CE应用程序开发者,你也一定遇到过下图这种场景: 这个对话框告诉你,有一个叫installer.exe的程序在地址00019320处崩溃了。如果这个程序归你负责,那么你的问题就

xqhrs232的专栏 1106

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

windows CE应用程序异常的调试方法——转载

无论你是一个单纯的电脑用户还是一名高级软件工程师,都一定对程序崩溃不陌生。做为一名Windows CE应用程序开发者,你也一定遇到过下图这种场景:这个对话框告诉你,有一个叫installer.exe的程序在地址00019320处崩溃了。如果这个程序归你负责,那么你的问题就来了:怎么找出这个BUG?这篇文章我想谈谈我在这方面的一些经验。Windows CE的崩溃界面给出的信息十分的少,其中最有用的无

gooogleman#foxmail.com 2201

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

vector iterators incompatible 删除map,list中元素时,应注意的问题

1.vector iterators incompatible 发现引发这个错误的代码如下:for (VectorType::iterator it = someVector.begin();; it != someVector.end();++it;){ if (*it== value) { someVector.erase(it); }}代码中,在eras...

weixin_33887443的博客 121

(转http://hi.baidu.com/adoblog/blog/item/102574233779ba4a925807c0.html):Vector发现的一个使用细节:vector it......

以前使用VC6开发,最近换用VS2005编译以前的程序,在运行时出现断言,切回 调试器,发现提示是 "vector iterators incompatible” 发现引发这个错误的代码如下: VectorType::iterator it = someVector.begin();...

chupu2979的博客 118

播放视频一会,出错并自动关闭

<br />系统:WINCE6.0+2443<br /> <br />上周遇到一个很奇怪的问题,之前上网播放视频的时候,没有出现播放一会就会出错并且自动关闭IE的情况,但后来测试到在播放视频大概50s的时候,总是会弹出下面的对话框并且自动关闭IE,这个对话框的内容如下:<br />application IEsample.exe encountered a serial error and must shut down<br /><br />串口输出的信息如下<br />Exception 'Data Ab

LoongEmbedded的专栏 2207
上一篇: 报错:error LNK2019: 无法解析的外部符号
下一篇: 关于ComboBox的控件事件CBN_SELCHANGE的问题
scorpiomiracle
博客等级 码龄17年 5粉丝 51原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值