How to read a PWM OUTPUT PIN value? How to get a pwm pin value that is in pinMode OUTPUT?

How to get a digital OUTPUT PIN value:

#define pin 3

void setup()
{
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
    delay(1000);
    digitalWrite(pin, HIGH);
    Serial.println(bitRead(PORTD,pin));
    delay(1000);
    digitalWrite(pin, LOW);
    Serial.println(bitRead(PORTD,pin));
}




For testing reasons, I want to get PWM output pin value.

Incorrect sketch:

#define pin 3

void setup()
{
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
    delay(1000);
    analogWrite(pin, 100);
    Serial.println(pulseIn(pin, HIGH)); // value of the PWM output pin
}


This sketch was created for example only.
I don't know PWM value because PWM value will be generating dynamically.
Could you explain how to get a PWM output pin value, please?
According to the source code implementation of analogWrite function
(Arduino analogWrite source code explanation).

You can use OCRnx register for reading PWM value.