[완료]Performance Counters 프로그램 작성 시 생기는 Access Violence 문제 -__-

superdma의 이미지

vs2008 express edition과 6.0에서 해당 소스파일을 컴파일 했는데
다음과 같은 오류가 나오더 군요...

Performance Counters.exe의 0x7c7db067에 처리되지 않은 예외가 있습니다. 
0xC0000005: 0xff28fc2e 위치를 읽는 동안 액세스 위반이 발생했습니다.

밤새 Performance Counters에 대한 구조를 공부하고 예제를 돌리는 순간 -_-...

OS Internal 깊숙한 문제 같아서 감이 잘 안 잡히네요..ㅠㅠ

Process 당 CPU 부하율 빨리 구해야 되는데, 처음부터 막히네요.

Perfmance Coutner 예제는 첨부했습니다.
http://lollab.com/mat/pdh/pdh1.pdf 문서에 제시된 코드 입니다.

File attachments: 
첨부파일 크기
Package icon perf2.zip2.37 KB
chadr의 이미지

깊숙한 문제는 아니구요.. 작성하신 코드에 문제가 있습니다.

NextInstance 함수의

PPERF_COUNTER_BLOCK PerfCntrBlk;
  PerfCntrBlk= (PPERF_COUNTER_BLOCK)( (PBYTE)PerfCntrBlk +
    PerfCntrBlk->ByteLength);

이 부분에 문제가 있습니다. 할당되지 않은 포인터에 PerfCntrBlk->ByteLength를 하고 있습니다.

그리고 여러가지 치명적인 에러가 될수 있는 warning이 많이 뜨고 있습니다.
-------------------------------------------------------------------------------
It's better to appear stupid and ask question than to be silent and remain stupid.

-------------------------------------------------------------------------------
It's better to appear stupid and ask question than to be silent and remain stupid.

superdma의 이미지

감사합니다.
디버깅에 서툴러서 미처 확인해 볼 생각도 못했네요.

NextInstance 함수를 다음과 같이 수정한 후 컴파일해도 이와 비슷한 다시 에러가 나네요.

PPERF_INSTANCE_DEFINITION NextInstance( PPERF_INSTANCE_DEFINITION PerfInst )
{
	PPERF_COUNTER_BLOCK PerfCntrBlk;
	PerfCntrBlk= (PPERF_COUNTER_BLOCK)( (PBYTE)PerfInst +
		PerfInst->ByteLength);
 
	return ( (PPERF_INSTANCE_DEFINITION)( (PBYTE)PerfCntrBlk +
		PerfCntrBlk->ByteLength) );
}
pER.exe의 0x7c7db067에 처리되지 않은 예외가 있습니다.
0xC0000005: 0xff28f826 위치를 읽는 동안 액세스 위반이 발생했습니다.

다시 한번 구조체 mapping 된거 보고 확인해 봐야겠네요...

ㅠㅠ..,. 제발 실수가 있길

cppig1995의 이미지

PerfInst의 다음 항목이 PerfCntrBlk에 들어갔는데 PerfCntrBlk의 다음 항목을 return하면 2칸 앞으로 가는 것 아닌가요?

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

chadr의 이미지

디버거를 붙여보세요. 디버거 붙이면 어디서 에러가 났는지 디버거가 알려줍니다.
그걸 토대로 watch창에 변수들 값을 넣어서 확인 해보세요.

소스가 있는데도 메시지로 나온 주소 값 가지고 디버깅 할려고 하니 무엇이 문제인지
알아내기 힘든 것입니다.
-------------------------------------------------------------------------------
It's better to appear stupid and ask question than to be silent and remain stupid.

-------------------------------------------------------------------------------
It's better to appear stupid and ask question than to be silent and remain stupid.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.