0

I have the following code in a DLL:

 #pragma data_seg("ABC")
 __declspec (dllexport) char abc[2000] = { 0 };
 #pragma data_seg()
 #pragma comment(linker, "-section:ABC,rws")

I have the following code in an executable:

extern "C" __declspec(dllimport) char abc[];
char *abcPtr = abc;
#define iVar0 (*(long *)(abcPtr))

int main()
{
    printf("Value: %d %p\n", iVar0, &iVar0);
    iVar0 = 66;
    printf("Value: %d %p\n", iVar0, &iVar0);

    char buffer[256];
    scanf_s("%s", buffer, 256);
}

When I run the first instance of the program I get:

Value: 0 0FC2A000
Value: 66 0FC2A000

If I run a second instance I get the following because they are using the same shared section:

Value: 66 0FC2A000 <- Notice the value here is set
Value: 66 0FC2A000

However if I change the value in the first instance using Visual Studio debugger, I can see that it changed in the memory location; however, I cannot see the value change if I rerun the second instance.

Why is the debugger not able to write the actual shared (memory) section?

user3716892
  • 101
  • 7
  • Are you sure the debugger is actually changing the content of the shared segment? It sounds like it is not, which would be a debugger issue, not a coding issue. You already proved that the code itself works fine. – Remy Lebeau Jun 09 '17 at 20:50
  • Since I had 2 application running and pointing to the same shared memory, I assume that the code is working fine because I see the values changed. When I change a value using the debugger in the first app, the second app does not see the change. – user3716892 Jun 12 '17 at 14:46
  • I'm guessing the debugger is not changing the value is Shared Memory; however, when I view that memory location (in the app where I'm changing the value via debuuger), the value has been changed. – user3716892 Jun 12 '17 at 15:41
  • @user3716892, do you debug two console apps and one dll project in the same solution? Which VS version did you use? As far as I know, we could edit the value if we enable the Edit and continue in debugging, whether it is related to this option? Anyway, please share us the detailed steps about how we could repro this issue. – Jack Zhai Jun 13 '17 at 07:37
  • @Jack Zhai, Visual Studio 2015, 1 dll to create the shared memory. 1 app running in the debugger loading the dll and setting the shared memory via the debugger. 2nd app running on the console loading the same dll. You can edit the value in the debugger but the second app doesn't see the change. – user3716892 Jun 15 '17 at 02:12
  • @user3716892, So you just run and debug the same console app, if so, how did you change the value in the first instance using Visual Studio debugger in your side? – Jack Zhai Jun 16 '17 at 02:35
  • I run 1 instance in the debugger and another on the command prompt – user3716892 Jun 17 '17 at 02:55
  • @user3716892, Could you get useful information from my answer? If it is helpful, you could mark it as the answer, if not, please feel free to let me know. – Jack Zhai Jun 27 '17 at 05:55
  • I found the same issue here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/dc5a1e20-7b88-4b38-a062-ed7b7ce57942/setting-a-value-in-the-debugger-of-a-shared-section?forum=vcgeneral which has been closed. – Jack Zhai Jun 27 '17 at 10:30

1 Answers1

0

I got the same result as yours:

enter image description here

My understanding is that certain value was not shared in the shared memory during debugging.

https://blogs.msdn.microsoft.com/oldnewthing/20040804-00/?p=38253/

Jack Zhai
  • 6,230
  • 1
  • 12
  • 20