"Cannot Write Memory" thrown

Jan 13 at 4:10 PM
Hi,

We are currently experiencing an issue when we attempt to get code coverage on our win32 executable. This doesn't seem to affect our other similar visual studio projects and comparisons with vcxproj and solutions etc doesn't seem to indicate any differences that would be the cause of this. (We have even copied the other projects code across so the executables code itself can be ruled out)

The exact message shown is...
[exec] Error: BreakPoint.cpp:51 Cannot write memory:[00000000000000F4]: 00000000014D100AInvalid access to memory location.
This seems to mostly affect our Windows2012 Server Build box, however we can replicate on windows 10 desktop machines but only when running the buildscript/task via an elevated (Admin) command prompt.

We have noticed that in this projects case for some reason the unittest executable is being detected 'twice' in the [info] output (not sure if this is the issue or why its happening). Is there anyway to get more verbose output to see if we can track down where this breakpoint is being prevented (i.e. what executable and where the problem exists).

Any help would be greatly appreciated.
Thanks
Coordinator
Jan 15 at 1:57 PM
Hello,

First, make sure you run OpenCppCoverage on a non optimized build as OpenCppCoverage supports only debug build.

Your error occurs when trying to register a line for coverage.
The impacted module is the one defined in the last line [info] Module: XXX is selected because it matches selected pattern.
By using the command line options --sources and --excluded_sources, you should be able to find impacted file. Maybe it can help you to understand the problem.

You can also run OpenCppCoverage with --verbose and send me the log for analysis.

I hope this will help,

OpenCppCoverage
Jan 17 at 3:03 PM
HI,

Thanks for the reply.

Following your suggestions we were able to to locate the file that was causing the issue:
[exec] [debug] Filename: c:\visualstudioprojects\gamesmanager\3.x.x\ugmtooliwininstallerexe\src\main.cpp is selected because it matches selected pattern: c:\VisualStudioProjects\GamesManager\3.x.x\ugmtooliwininstallerexe\src
[exec] [debug] Executable lines for c:\visualstudioprojects\gamesmanager\3.x.x\ugmtooliwininstallerexe\src\main.cpp:
[exec] [debug] [14, 16, 21, 22, 23, 24, 25, 31, 32, 34, 37, 39, 41, 44, 45, 46, 48, 50, 52, 57, 59, 61, 63, 65, 66, 69, 71, 72, 75, 77, 79, 81, 83, 86, 89, 95, 96, 99, 100, 102, 105, 107, 108, 111, 112, 115, 116, 118, 121, 124, 126, 128, 130, 133, 137, 138, 141, 143, 146, 148, 149, 150, 152, 155, 161, 162, 164, 166, 167, 168, 170, 171, 173, 174, 176, 177, 179, 180, 182, 186, 187, 188, 190, 192, 193, 195, 197, 198, 199, 201, 203, 204, 206, 207, 210, 212, 215, 216, 217, 218, 219, 221, 223, 224, 226, 227, 229, 230, 232, 233, 235, 236, 238, 240, 241, 242, 243, 245, 247, 248, 252, 253, 256, 257, 258, 262, 263, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 283, 284, 287, 288, 290, 293, 295, 298, 300, 303, 305, 306, 309, 311, 312, 315, 318, 319, 321, 322, 325, 326, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 340, 343, 345, 347, 348, 349, 352, 353, 354, 355, 359, 361, 362, 363, 364, 366, 369, 373, 375, 377, 378, 380, 390, 392, 393, 395, 396, 399, 400, 403, 406, 407, 408, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 424, 426, 427, 428, 430, 432, 435, 437, 440, 442, 453, 456, 457, 458, 460, 463, 467, 470, 472, 475, 479, 480, 483, 484, 485, 486, 487, 488, 490, 492, 493, 494, 497, 498, 499, 500, 501, 502, 505, 506, 507, 508, 509, 510, 512, 514, 516, 520, 522, 524, 525, 528, 529, 530, 532, 533, 535, 538, 539, 541, 546, 547, 548, 549, 550, 552, 553, 554, 555, 556, 558, 560, 561, 562, 563, 567, 568, 569, 570, 572, 573, 575, 576, 577, 579, 581, 582, 583, 587, 588, 591, 592, 593, 594, 596, 597, 599, 600, 601, 604, 606, 608, 609, 610, 614, 615, 618, 619, 620, 622, 623, 625, 626, 627, 629, 631, 632, 633, 637, 640, 641, 642, 644, 645, 647, 648, 649, 651, 653, 654, 655, 659, 662, 663, 664, 666, 667, 669, 670, 671, 673, 675, 676, 677, 681, 684, 687, 688, 689, 690, 692, 694, 696, 699, 700, 701, 702, 704, 706, 708, 710, 711, 712, 714, 716, 718, 719, 720, 721]
[exec] Error: BreakPoint.cpp:51 Cannot write memory:[00000000000000D4]: 00000000009E474AInvalid access to memory location.
Following this I stripped down the contents of the file to the following:
1 #include <Windows.h>
2 
3 int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
4 {
5   return 0;
6 }
This resulted in the following output:
[debug] Filename: c:\visualstudioprojects\gamesmanager\3.x.x\ugmtooliwininstallerexe\src\main.cpp is selected because it matches selected pattern: c:\VisualStudioProjects\GamesManager\3.x.x\ugmtooliwininstallerexe\src
[debug] Executable lines for c:\visualstudioprojects\gamesmanager\3.x.x\ugmtooliwininstallerexe\src\main.cpp:
[debug] [4, 5, 6]
Error: BreakPoint.cpp:51 Cannot write memory:[00000000000000E0]: 0000000000893C50Invalid access to memory location.
Any ideas what the issue could be?
Coordinator
Jan 20 at 11:43 AM
Hello,

I created a project under Visual Studio 2013 and copy past your code. I ran cmd.exe with administrator rights then I ran OpenCppCoverage. I was unable to reproduce your issue.
Memory address 00000000000000E0 is very suspicious because it is not a valid address ASM code. Can you check you have no optimization enabled (only /Od is supported now).

Are you able to reproduce the problem on a toy project?
I will also try to make additional tests.

I hope this will help,

OpenCppCoverage
Jan 23 at 2:56 PM
Hi,

Thanks for the response.

Optimisation is disabled for the project with a setting of '/Od'. We cannot reproduce this issue in toy (or any of our other) projects. The projects settings between the projects that do work and the project that doesn't work appear to be the same.

Thanks for your time.

Cheers,

David.
Coordinator
Jan 25 at 8:52 PM
Edited Jan 25 at 9:01 PM
Hi,

I did a simplified version of what OpenCppCoverage does here.
Can you run your project on it?

I expect you will have an issue with ReadProcessMemory or WriteProcessMemory. If it is the case, can you post the values of:
  • lineInfo->Address
  • lineInfo->ModBase
  • processBaseOfImage
  • addressValue
You can also try to investigate why addressValue has a value near 0 in your case.

Note:
  • You can add a filter for your source files line 168 and 169.
  • Your working directory should contain the pdb files.
Please let me know if you find anything,

OpenCppCoverage
Marked as answer by OpenCppCoverage on 4/8/2017 at 5:07 AM